Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling binary data with SOAP

I have been investigating how to handle binary data with SOAP messages. I am developing both the client and the service so i have the option of choosing whichever framework. The only constraint is that the Service end has already been designed and is based on Spring-WS.

Looking at google, it looks like there are three options:

  • Sending the attachment inline as base64 in the SOAP message (Base64Binary).
  • Sending the attachment outside of the SOAP message. i.e. with a reference to the attachement (SWA)
  • Sending the attachement outside the message but make it appear as though it is embedded in the message (MTOM).

Questions

  • What exactly does it mean when they say that the attachement is outside of the SOAP message? I assume that maybe the attachement is sent as a different TCP package but i think i am wrong?

  • Which of the above options is recommended and specifically, which one works best with Spring's Spring-WS framework?

  • It is unclear to me which of the above options encode the binary content during transmission. What is Binary MIME as described here - http://www.crosschecknet.com/intro_to_mtom.php ? Is the binary data still converted to text during transmission?

  • What is the format of the data when using SWA?

like image 710
ziggy Avatar asked Apr 01 '12 20:04

ziggy


1 Answers

What exactly does it mean when they say that the attachement is outside of the SOAP message? I assume that maybe the attachement is sent as a different TCP package but i think i am wrong?

In contrast to the first option the attachment is not part of the actual soap message payload but instead referenced to within the SOAP document. The difference between MTOM and SWA is where the referenced file is located. For MTOM it's embedded in the response, while in SWA you could for example get a link to the resource on the web. It follows 3 minimal examples:

MTOM (all in one response of type xop+xml)

Content-type: multipart/related;
type="application/xop+xml";
start-info="text/xml"

--uuid:c73c9ce8-6e02-40ce-9f68-064e18843428
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version="1.0" ?>
  <S:Envelope xmlns:S="...">
     <S:Body>
      <ns2:downloadImageResponse xmlns:ns2="...">
         <return>
           <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" 
         href="cid:[email protected]">
           </xop:Include>
         </return>
      </ns2:downloadImageResponse>
     </S:Body>
   </S:Envelope>
--uuid:c73c9ce8-6e02-40ce-9f68-064e18843428
Content-Id: <[email protected]>
Content-Type: image/png
Content-Transfer-Encoding: binary

SWA (only reference)

Content-Type: application/xml;charset=utf-8;

<?xml version="1.0" ?>
  <S:Envelope xmlns:S="...">
     <S:Body>
      <ns2:downloadImageResponse xmlns:ns2="...">
         <return>
           https://server.com/downloadImagehere.png
         </return>
      </ns2:downloadImageResponse>
     </S:Body>
   </S:Envelope>

Inline

Content-Type: application/xml;charset=utf-8;

<?xml version="1.0" ?>
  <S:Envelope xmlns:S="...">
     <S:Body>
      <ns2:downloadImageResponse xmlns:ns2="...">
         <return>
           YTM0NZomIz...potentiallyLargeBase64encodedFileGoesInHere...I2OTsmIzM0NTueYQ==
         </return>
      </ns2:downloadImageResponse>
     </S:Body>
   </S:Envelope>

Which of the above options is recommended and specifically, which one works best with Spring's Spring-WS framework?

They are all supported, and the one to use depends a bit on your use-case. MTOM seems to be the de-facto standard according to my research. According to me it it's particularly useful if you have either large or multiple file attachements. Since it splits the message in it's logical components it might give the parser more options to handle the binary data efficiently.

However, for smaller data I would probably go for the embedding of the resource, since it's part of the standard SOAP protocol and only uses an encoded byte array directly which is then directly embedded into the message. If portability/compatibility is important this might be the approach to choose.

The last approach obviously requires you to handle the reference by yourself, which might or might not be what you want.

It is unclear to me which of the above options encode the binary content during transmission. What is Binary MIME as described here - http://www.crosschecknet.com/intro_to_mtom.php ? Is the binary data still converted to text during transmission?

MTOM and Inline both encode the file usually as Base64encoded String. For external links it's not relevant.

What is the format of the data when using SWA?

Base64encoded byte array

like image 80
Christian F Avatar answered Sep 29 '22 20:09

Christian F