Adding attachments to web service

Hi,
I am working on a project which requires me to add pictures as attachments of a web service.
This is what I do:
messageContext = endpointContext.getMessageContext();
SOAPMessageContext soapContext = (SOAPMessageContext) messageContext;
SOAPMessage msg = soapContext.getMessage();
//URL url = new URL("file:///attachments/jhe061.gif");
URL url = new URL("http://www.google.ro/images/hp0.gif");
DataHandler dataHandler = new DataHandler(url);
AttachmentPart attachment = msg.createAttachmentPart(dataHandler, "image/gif");
attachment.setContentId("image/gif");
msg.addAttachmentPart(attachment);
According to the J2EE tutorial, an image attachment should be added to the service. On the client side no sign of a multipart is found....
Could anybody tell me what I do wrong?
Thanks, d3m0

Attachment support for webservices is not defined using the mime binding in the
current jaxrpc1.1 implementation. It is done in an implementation specific manner.
See the jaxrpc1.1 specfication chapter 7 where it talks about SOAP messages with
attachments. This is optional functionality in the jaxrpc1.1 release.
In jaxrpc1.1.2 (a follow on release) support for WS-I Attachment Profile1.0 is
in this release defined via the wsdl mime binding. You can get this release by
downloading the JWSDP1.4 release. This contains the required attachment support
you need for handling attachments in webservices in a portable way. To create
a webservice with attachments using this release is quite easy. You simply
define your attachments in your wsdl using the wsdl mime binding. You can send
attachments to a webservice in the SOAP request by defining the mime binding
on the operation input and you can get attachments back from the webservice by
defining the mime binding on the operation output. You will need to look at
at the WS-I Attachment Profile 1.0 Specification to see how this is done.
Also look at the documentation and release notes for the JWSDP1.4 release.
Here is an example of the mime binding for a webservice operation on the
output.
<binding name="SwaTestSoapBinding1" type="tns:SwaTest1">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="getMultipleAttachments">
<soap:operation/>
<input>
<soap:body parts="request" use="literal" namespace="http://SwaTestService.org/wsdl"/>
</input>
<output>
<mime:multipartRelated>
<mime:part>
<soap:body parts="response" use="literal" namespace="http://SwaTestService.org/wsdl"/>
</mime:part>
<mime:part>
<mime:content part="attach1" type="text/plain"/>
</mime:part>
<mime:part>
<mime:content part="attach2" type="text/html"/>
</mime:part>
</mime:multipartRelated>
</output>
</operation>
An example of using attachments in jaxrpc1.1:
To do attachments in jaxrpc1.1 you can start from java and develop an SEI with
signatures as follows:
Sample SEI
package attachmentstest;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.awt.Image;
import javax.mail.internet.MimeMultipart;
import javax.xml.transform.Source;
import javax.activation.DataHandler;
import java.util.*;
// Service Defintion Interface - as outlined in JAX-RPC Specification
public interface AttachmentsTest extends Remote {
public Image echoImage(Image v) throws RemoteException;
public Image[] echoImageArray(Image[] v) throws RemoteException;
public MimeMultipart echoMimeMultipart(MimeMultipart v) throws RemoteException;
public MimeMultipart[] echoMimeMultipartArray(MimeMultipart[] v) throws RemoteException;
public Source echoSource(Source v) throws RemoteException;
public Source[] echoSourceArray(Source[] v) throws RemoteException;
public DataHandler echoDataHandler(DataHandler v) throws RemoteException;
public DataHandler[] echoDataHandlerArray(DataHandler[] v) throws RemoteException;
Sample Client
private boolean dataHandlerTest() {
     TestUtil.logMsg("AttachmentsTest:(dataHandlerTest)");
     boolean pass = true;
     DataHandler response;
try {
DataHandler dataHandler = new DataHandler(sourceFileURL);
     TestUtil.logMsg("Test request/response of DataHandler ...");
     TestUtil.logMsg("dataHandler="+dataHandler);
     response = port.echoDataHandler(dataHandler);
     if (!(response.getContent().equals(dataHandler.getContent()))) {
          TestUtil.logErr("DataHandler comparison mismatch");
          pass = false;
} catch (Exception e) {
     TestUtil.logErr("Caught exception: " + e.getMessage());
TestUtil.printStackTrace(e);
     pass = false;
     printTestStatus(pass, "AttachmentsTest:(dataHandlerTest)");
     return pass;
private boolean sourceTest() {
     TestUtil.logMsg("AttachmentsTest:(sourceTest)");
     boolean pass = true;
     Source response;
try {
Source source = new StreamSource(xmlFileURL.openStream());
     TestUtil.logMsg("Test request/response of Source ...");
     response = port.echoSource(source);
     // Code for comparison here
} catch (Exception e) {
     TestUtil.logErr("Caught exception: " + e.getMessage());
TestUtil.printStackTrace(e);
     pass = false;
     printTestStatus(pass, "AttachmentsTest:(sourceTest)");
     return pass;

Similar Messages

  • Adding attachments to Web Service call

    Hi
    Does Bea's web service classes include support for adding attachments to the soap message sent by a web service?
    How do I do it? or otherwise, how do I get through the abtraction down to the soap message so I can add it manually?
    I have both a weblogic.webservice.core.rpc.StubImpl and a javax.xml.rpc.Service to work with, I'm guessing it's somewhere deep down in the context of the Service...?

    Hi
    Does Bea's web service classes include support for adding attachments to the soap message sent by a web service?
    How do I do it? or otherwise, how do I get through the abtraction down to the soap message so I can add it manually?
    I have both a weblogic.webservice.core.rpc.StubImpl and a javax.xml.rpc.Service to work with, I'm guessing it's somewhere deep down in the context of the Service...?

  • Error occured while Adding a reference Web Service(BizTalkServer2009_Tutorial2)

    Hi,
    I was going through the Biztalk tutorials. While doing the second tutorial of web service I got stuck while adding reference to the Web Service.
    Steps I did:
    Add service reference(by right clicking my project) --> Advanced -->  Add Web Reference -->  URL : http://localhost/b2bsupplierprocesspo/process.asmx
    But somehow this URL is not accesible over there. I got following error:
    Please suggest/guide me on this.
    Thanks, Girish R. Patil.

    The error clearly states the reason for failure, being "CS0016: Could not write to output file ..... ..... - Access is denied."
    The directory in question is the "C:\Windows\Microsoft.Ner\Framework\v2.0.50727\Temporary ASP.NET Files". So two things
    Does the tutorial mention that the Web Service should be hosted under a .Net V2.0 Application Pool? If so then please give "Full Control" permissions to the above directory for the BizTalk Service Accounts (which also should be part of your "BizTalk Isolated
    Host Users" Group.
    If not then the service has to be hosted in a .Net v4.0 app pool. Change the Application Pool Settings through IIS Manager and give permissions to a similar folder (Temporary ASP.Net) but under the Framework\V4.0.... directory.
    Regards.

  • Problem while Adding the SAP Web service in Visual Studio 2005

    Hi all,
    I have created the web service thru SOAMANAGER.
    Now I am just trying to access that web service in Visual Studio 2005.
    I am not able to access...
    Please give me the procedure , if any body knows.
    -Balajee Jeyaraj.

    - Start Tcode SOAMANAGER
    - Now it depends on your setup, you might have to press "Logon" and.......logon
    - Click tab "Business Administration"
    - Click "Web Service Administration"
    - Choose "Service" for "Search by"
    - Enter a search pattern (E g Z*) and press "Go"
    - Mark the line of your web service
    - Press "Apply Selection"
    - Click the link "Open WSDL document for selected binding"
    - your web browser opens.
    - copy and paste the link into Visual Studio.
    I'm always adding    &wsdl=1.1     at the end of the link.

  • Problem in adding a new web service provider system in NWA SOA

    Hello,
    Portal version : CE7.3 EHP1 SP9
    I am trying to add a web service system in "NWA > SOA > Technical Configuration > System Connections > Provider Systems > New".
    I have web service WSDL URL with me which is like: -
    https://webservicehostname/dswsbobje/qaawsservices/biws?WSDL=1&cuid=AfO9g_JmE0ZOiZzdvNtCbxg
    When I enter this URL in input field "WSIL URL" and click on "Next", I get error saying: -
    "Cannot connect to https://webservicehostname:443/dswsbobje/qaawsservices/biws?WSDL=1&cuid=AfO9g_JmE0ZOiZzdvNtCbxg
    HTTP Message : Unable to connect to webservicehostname:443 - Connection refused".
    (attached screenshot)
    Now, it puzzles me that why & how it is appending colon & port number in the entered URL as protocol is already https?
    Basis & network team is looking into connectivity related settings, but from my side, I wanted to answer/know why & how this port number is getting appended in entered URL and how to prevent it.
    Any ideas/help please.
    Thanks & Regards,
    Amey Mogare

    Hello Atul,
    In WSDL URL and content itself, there is no port number specified as protocol used is https.
    (screenshot).
    The problem is, after clicking on "Next", system is somehow inserting port number in between URL which it ideally should not as URL protocol is https.
    Thanks & Regards,
    Amey Mogare

  • Adding Faults to Web Services created from JCDs

    Is anyone aware of a way to add faults, other than the default JavaException, to the service definition of a web service created from a JCD?

    Hi
    You could use se80 and click "Repository Information system"->Enterprise Services->
    Service Definitions->search your WebService Defition->Delete it.

  • Adding Authentication to Web Service using JDeveloper

    Hi Gurus,
    I am new to weblogic 10.3 and Jdeveloper 11.1.3. Using Jdeveloper, I imported few packages from database , right clicked and published them as a webservice on a weblogic server. I did not select any WLS policies. The web service is working fine. Now i want to add some basic authorization (username/password) to this webservice.
    Which policy should i use ?
    Where should i configure this username\password so that all the webservices uses same user for authenctication ? Do i have to create this user on the weblogic server? If yes then how.
    Thanks in Advance.
    Jack

    Hi,
    If you are using JAXWS based WebService then you can give it a try:
    http://weblogic-wonders.com/weblogic/2010/01/09/username-token-in-jaxws-webservice/
    This sample demonstrates ..How we can use UserName/Password Authentication in JAXWS Service. This will be very Easy for you to develop using JDeveloper...U need to Just the add Following XML file as a Policy inside your Application.
    Using the following Policy:
    <font color=maroon>
    <?xml version=”1.0″?>
    <wsp:Policy
    xmlns:wsp=”http://schemas.xmlsoap.org/ws/2004/09/policy”
    xmlns:sp=”http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512″>
    <sp:SupportingTokens>
    <wsp:Policy>
    <sp:UsernameToken
    sp:IncludeToken=”http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512/IncludeToken/AlwaysToRecipient”>
    <wsp:Policy>
    <sp:WssUsernameToken10/>
    </wsp:Policy>
    </sp:UsernameToken>
    </wsp:Policy>
    </sp:SupportingTokens>
    </wsp:Policy>
    </font>
    Thanks
    Jay SenSharma

  • Adding Functions to Web Services

    Never mind, it's something else.

    Hi,
    If you have web service in source and target, we can choose SOAP adatper
    External system--SOAP(Sender) PI SOAP(Receiver)--
    External system
    Configure IR & ID objects according to your requirement and take communication channels SOAP for sender & receiver.  At sender soap adapter no inputs required, if u go for authentication need to enable that option.
    SOAP receiver end need to give system name, service no and path
    Refer below links will help u
    Invoke Webservices using SAPXI

  • How to send Attachments vis web service response?

    Have created a custom plsql type webservice.
    How do we send a file(say a blob object) as an attachment?
    Cannot be sent as a blob object return parameter.
    Any body have encountered this requirement?

    Hi Abdullah,
    this is only possible if there is an extension scenario for the Query "Outbound" available. You added already the "Inbound" Query but I am pretty sure that there is a second scenario for the QueryCustomerIn for the "Outbound".
    Just check out the available options of the process extension scenario you are using already and you will find it. Check it, activate your xbo and the response should also have your field
    Cheers,
    Jens

  • Attachments in web services

    hi all,
    I posted my msg last week , i like to post it again because its not solved.thanks.
    I am runing the example for attachment
    "http://dev2dev.bea.com/managed_content/direct/webservice/swaParam.zip"
    & i am getting this error, saying its wrong no. of arguments, but i have checked its rite in the example have anyone tried...
    run:
    [java] From server::helloWorld
    [java] java.rmi.RemoteException: SOAP Fault:javax.xml.rpc.soap.SOAPFaultExc
    eption: wrong number of arguments; nested exception is:
    [java] javax.xml.rpc.soap.SOAPFaultException: wrong number of arguments
    [java] javax.xml.rpc.soap.SOAPFaultException: wrong number of arguments
    [java] at weblogic.webservice.core.DefaultOperation.invoke(DefaultOpera
    tion.java:459)
    [java] at weblogic.webservice.core.DefaultOperation.invoke(DefaultOpera
    tion.java:359)
    [java] at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:2
    25)
    [java] at examples.webservices.basic.attach.MyServicePort_Stub.echoAtta
    chment(MyServicePort_Stub.java:33)
    [java] at examples.webservices.basic.attach.Client.main(Client.java:22)
    [java] Exception in thread "main"
    Thanks
    Diwa

    Hello,
    When you deployed the "attach.war" and used the browser to look at the test page: http://localhost:7001/attach/MyService do you
    see two operations: echoAttachments and helloWorld? When you select helloWorld, and do the Invoke, does it display the soap
    request/response?
    Could you do a "java weblogic.version"
    Are you using WLS v7.0 SP1?
    Thanks,
    Bruce
    Diwa wrote:
    hi all,
    I posted my msg last week , i like to post it again because its not solved.thanks.
    I am runing the example for attachment
    "http://dev2dev.bea.com/managed_content/direct/webservice/swaParam.zip"
    & i am getting this error, saying its wrong no. of arguments, but i have checked its rite in the example have anyone tried...
    run:
    [java] From server::helloWorld
    [java] java.rmi.RemoteException: SOAP Fault:javax.xml.rpc.soap.SOAPFaultExc
    eption: wrong number of arguments; nested exception is:
    [java] javax.xml.rpc.soap.SOAPFaultException: wrong number of arguments
    [java] javax.xml.rpc.soap.SOAPFaultException: wrong number of arguments
    [java] at weblogic.webservice.core.DefaultOperation.invoke(DefaultOpera
    tion.java:459)
    [java] at weblogic.webservice.core.DefaultOperation.invoke(DefaultOpera
    tion.java:359)
    [java] at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:2
    25)
    [java] at examples.webservices.basic.attach.MyServicePort_Stub.echoAtta
    chment(MyServicePort_Stub.java:33)
    [java] at examples.webservices.basic.attach.Client.main(Client.java:22)
    [java] Exception in thread "main"
    Thanks
    Diwa

  • LV2012 Web Services w/ NI Auth login not working w/ static files in Firefox 19

    Hi!
    I followed this procedure to password protect my web service and the static files. 
    http://digital.ni.com/public.nsf/allkb/DF41D5DA8EEB4840862577D90058C208
    When testing it out with my web service it seems to work fine on any web browser.  http://localhost:8080/add/add/1/2 first will present a login.  Once the user is logged in the page refreshes and the results of the operation are shown.  http://localhost:8080/logout works as well.
    I followed the procedure in the FAQ to include an index.html file.
    http://www.ni.com/white-paper/7747/en#toc15
    When I try to access the page (via http:localhost:8080/add/web/index.html) I'm greeted with the National Instruments login screen.  I enter my credentials and in Chrome and Internet Explorer the screen refreshes and I see my html file.  In Firefox it hangs for awhile on the authentication screen and then reloads back to the authenticaiton screen (as if the username and password did not take).
    Attached are my files.  If you want to try and recreate this please follow this procedure:
    * Unzip the attached project to a folder
    * Open the project in LabVIEW 2012
    * Check the properties of the web service to ensure that the build paths are correct
    * Follow the procedure above for setting up NI Auth on your web service and adding the "testpermission2" permission.  Be sure to remove "Everyone" from that "testpermission2" or you will never see a login prompt.
    * Build/Deploy the web service
    * open http://localhost:8080/logout to ensure that you are not currently authenticated
    * open http://localhost:8080/add/add/1/2 and login, observe behavior
    * open http://localhost:8080/add/web/index.html you should still be logged in so you will see the "Hello World!" just fine
    * open http://localhost:8080/logout to log back out
    * open http://localhost:8080/add/web/index.html and see if you are able to login.
    I've tried disabelling my plugins in Firefox and still have this problem.  I'm really scratching my head on how to overcome this other than throwing away NI Auth and use something else.  My web service is going to run off of a static front end driven by javascript and html.  So the access point will be the html file.  I need to have some username and password scheme worked out.  I also need to be able to see what user is currently logged in with my Web Service VIs (does anyone know if that is possible with NI Auth)? 
    The other BIG issue I have with NI Auth is that it requires Silverlight.  So much for mobile support, eh?  Anyone know of a good plug-and-play alternative so I don't have to reinvent the wheel?  I guess I could impliment some kind of token system on my web service side.
    In the meantime, getting NI Auth to properly work with Firefox would help.
    Thanks for your input,
    -Nic
    Attachments:
    Example Web Service.zip ‏15 KB

    Disclaimer: I in no way mean to bash NI and I have used NI Auth myself in the past
    If you are going to go to the trouble of abstracting NI Auth, I would recommend instead investing your time in your own authentication scheme (or implementing a standard scheme in LV).
    NI Auth is great and works for low security applications where you just don't want people fooling around with your application who shouldn't be.
    However, NI Auth is really not that secure.  If I remember correctly, the username is transmitted in plain text and I don't think the encryption algorithm is that sophisticated.  It is nice that it's already integrated into LV, but there really are very few features at this time.
    If you want something to be really secure, you need to take measures beyond what NI Auth provides and before you go to the work of building abstraction on top of a basic and somewhat shaky protocol, I'd seriously consider implementing a more stable base.
    <insert 2 cents complete>
    Chris
    Certified LabVIEW Architect
    Certified TestStand Architect

  • EJB3 Entities + Web Services: A cycle is detected in the object graph

    I have a Java EE 5 application, using Glassfish v2. My ejb project consists of a handful of entity beans, session beans, and this problem arose when I added a new web service.
    Here is a simple scenario borrowed from another forum post with a similar problem:
    Let's say I have a web service called getVehicle(int vehicleId) that returns a Vehicle object.
    Vehicle has a java.util.Set of Wheel objects.
    The Wheel object has a reference to its owner (Vehicle).
    The issue is this bi-directional relationship causes a cycle that the JAX system doesn�t like.
    Caused by: javax.xml.bind.MarshalException
    - with linked exception:
    [com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: org.test.Vehicle at 13c6308 -> org.test.Wheel at 15880be -> org.test.Vehicle at 13c6308
                  at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:282)
                  at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:110)
                  at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:178)
                  at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:299)
                  ... 54 more
    The one bit of information that I found that might fix this doesn't do much for me:
    https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html
    What options do I have to make my soap method work?
    Thanks,
    Hugh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    i have got the same issue�C
    how did you implement onCycleDetected method�H
    can you send your full code to my mail [email protected]
    thanks !

  • Error occurs when i try to install a built application containing Web services VIs

    Hello,
    at the moment i am trying to create and install a built application containing a Web server and Web services VIs. I did the steps as described here: http://www.ni.com/white-paper/7747/en#toc13
    But when I install my application on the target PC the following error occurs after the installation:
    Error2: Failed to perform action
    "[LV2011RTEDIR]LVWS\NILVWSPostInstallerScript.exe"
    "[ProgramFilesFolder]DeployWebServices\Webservice.lvws"
    What did I do wrong? The project example is attached
    Development system: LV2011 SP1, WIn7
    Target PC: Win7, no LabVIEW, but ALL possible additional installer/run-times installed
    Thanks,
    Elmar
    Certified LabVIEW Developer
    www.merecs.de
    Attachments:
    Deploy Web Services.zip ‏20 KB

    Hi,
    long time ago, but I can remember. You have to copy a folder.
    e.g. I have the file in C:\Program Files (x86)\National Instruments\Shared\LabVIEW Run-Time\2013\LVWS , but there is no LVWS folder in \Shared\LabVIEW Run-Time\2012
    (I have a new computer, and for some reason I'm also missing the file in the LV2012 folder now.)
    Try to copy from another version to 2012 U(or download my fzip). I also don't now, why it is missing. Maybe something during the LV2012 installion was wrong.
    Hope I could help,
    Elmar, CLD
    Certified LabVIEW Developer
    www.merecs.de
    Attachments:
    LVWS.zip ‏688 KB

  • Certain data missing from Web service output in LV8.5.1

    I just installed Labview 8.5.1 and thereby got rid of a problem where the Import Web Service Wizard hung.
    However, a new problem appeared. The XML output of my web service call does not contain the actual result values. When I call the web service using SOAPUI from http://www.soapui.org/, I can see the actual result values in a section of the XML output called diffgr:diffgram. When I inspect the Labview XML output, the whole diffgram section is missing! Se attachments.
    Any help appreciated!
    Attachments:
    SOAPUI Web Service output2.txt ‏3 KB
    Labview Web Service output1.txt ‏1 KB

    It is on our company's intranet. The description in wsdl-format is attached.
    (You might have to save it as a .txt file on your hard drive in order to view it with Notepad.)
    Message Edited by andreas nilsson on 04-23-2008 05:47 AM
    Attachments:
    Axaptaws_wsdl.txt ‏146 KB

  • Web services in Flex

    Hi all,
    I am trying to figure out if there is a way to send / receive
    file attachments using web services. I have read a bit about
    converting attachments using Base64 to convert binary to text. I am
    hoping there is a better way to do this as most of my file
    attachments are fairly good size.
    Any thoughts? Samples? etc . .
    Thanks,
    STeveR

    Hi,
    Currently, Flash Player 9 does not let you access the
    contents of a file on the client side (though this is possible in
    AIR / Flash Player 10). Once you have access to the file contents,
    you can use Base64, hex encoding etc.
    DIME is an alternative. But Flex has no API support for it.
    You could submit a feature request at
    http://www.adobe.com/go/wish
    or try extending
    SoapEncoder
    to support DIME.

Maybe you are looking for