Get your CodeRanch badge!*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes SOAP with Attachment. and WSDL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "SOAP with Attachment. and WSDL" Watch "SOAP with Attachment. and WSDL" New topic
Author

SOAP with Attachment. and WSDL

Khaled Mahmoud
Ranch Hand

Joined: Jul 15, 2006
Posts: 361
Hello,

I think I have a bit of confusion regarding SOAP with attachments.

I know that in SOAP with attachments. I can attach various attachments with various type, for example :

  • Binary attachments encoded with Base64
  • Direct binary attachments


  • The whole SOAP message is encapsulated and sent within a MIME message.
    My question is :
    If I used SOAP with attachments, is this described in the WSDL file ??? Since a tag in the message will reference an attachment within the MIME message, how can this be described in WDSL, or this is beyond the scope of WSDL and can JAX-WS be used in case of SOAP with attachments ??

    Thanks in advance






    SCJP, SCJD,SCWCD,SCDJWS,SCEA 5 MCP-C#, MCP-ASP.NET - http://www.khaledinho.com/
    Life is the biggest school
    Victor Bucutea
    Ranch Hand

    Joined: Nov 24, 2008
    Posts: 43
    Hi Khaled,


    SOAP attachements are not enabled by default. If you were do deploy a service like this :


    the Image object would be returned to the client, depending on the SOAP style ( document or rpc ), as an BASE64 encoding right into the XML .



    this would be the HTTP response headers :




    and this would be the SOAP response:

    <?xml version="1.0" ?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
    <ns2:retrievePictureResponse xmlns:ns2="http://service.ivan.com/">
    <return xmlns="">iVBORwEWDx...</return>
    </ns2:retrievePictureResponse>
    </S:Body>
    </S:Envelope>


    However, if you would use the @MTOM annotation when deploying, like this:


    Take note that MTOM is used as an optimization of transferring large amounts of data through soap.
    The server would optimize binary transfers through SOAP, that is use the attachment part of the SOAP message to encode the Image:

    HTTP response headers:




    And this would be the WSDL generated by the appserver :



    So to answer your question, yes in the case of MTOM, there are clear specifications in the WSDL ( wsp:Policy elements ) on how to encode large binary attachments into the SOAP message. For a weird reason I cannot get the SOAP attachment to work ( it's something related to my client JARs ), but you can see it in depth in Ivan Kriszan notes chapter 10.3.

    And BTW , ALL binary transfers are Base64 encoded. There is no such thing as a Direct binary attachment.




    PS all of this are based on what Ivan Kriszan has explained in his notes. This example is not mine.
    Thanks,
    Victor
    Ivan Krizsan
    Ranch Hand

    Joined: Oct 04, 2006
    Posts: 2198
        
        1
    Hi!
    For the cases where MTOM is not used, take a look at the following references:
    MIME binding in WSDL 1.1: http://www.w3.org/TR/2001/NOTE-wsdl-20010315#_Toc492291084
    Attachment description in the WS-I Attachments Profile 1.0: http://www.ws-i.org/Profiles/AttachmentsProfile-1.0.html#WSDLMIMEBINDING

    The short answer to your question is: yes.
    Best wishes!
    Khaled Mahmoud
    Ranch Hand

    Joined: Jul 15, 2006
    Posts: 361
    Hi,

    Thanks for your reply. Surely I have to read about MTOM.

    But I have one small comment on what you said regarding binary attachments.


    And BTW , ALL binary transfers are Base64 encoded. There is no such thing as a Direct binary attachment.


    I have read in a course I download directly from Sun for free [Web Services Enabling Technologes], is that the whole SAOP request can be encapsulated within a MIME message, which contains both the SOAP request as the first attachment and the other attachments.The other attachments can have any encoding, not necessarily Base64, and be inserted in the request as is (Not necessarily base64).

    The example which the course listed




    Here is the link for the course :

    http://www.sun.com/training/catalog/courses/WJO-1118.xml


     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: SOAP with Attachment. and WSDL
     
    Similar Threads
    Binding Doubts
    Does JAX-WS require that attachments be base64 encoded?
    how to transfere larg XML content using a web service?
    encoding style: literal vs encoded
    sending pdf or any attachment from a java webservice to java client using JAX-WS and SAAJ