Saturday, September 13, 2008

Attachments - MTOM, SWA and Base64Binary Compared

Sending Attachments in Web Services is a common use case and there are various ways in which this objective could be achieved. Sending the Attachments as MTOM (SOAP Message Transmission Optimization Mechanism), SWA (SOAP with Attachments), or Base64Binary are some of your options.

Here is a simple comparison between these 3 options.
  • base64Binary sends the attachments as base64 inline in the SOAP message. i.e. The Attachment in embedded in the SOAP Message. Bloats the message by 33%.
  • SWA sends the Attachment outside the SOAP message (The SOAP message contains a reference to the attachment). But the SOAP infoset does not contain the attachment
  • MTOM Provides the best of both world. The Attachment is sent outside the SOAP message with a reference to it but the attachment appears as if it is embedded in the SOAP message (The SOAP infoset contains the attachment)
Due to the fact that attachments sent using MTOM appear as it the attachment is part of the SOAP message it allows you to use other WS-* QOS (Quality of Service) attributes. For e.g MTOM messages can be signed and encrypted using WS-Security. Thus this provides a mechanism to send Secured Attachments without the need for additional specs.

Axis2 as well as (WSO2 WSAS) supports all three of the above mechanisms. In a later post I will describe how each of the above can be used and how the actual wire messages look.

5 comments:

Unknown said...

Does Axis2 honor the "threshold" setting for MTOM? I know that JAXWS currently doesn't honor the threshold.

Keith Chapman said...

What do you really mean by "threshold setting for MTOM"?

Yaron Naveh (MVP) said...

I think what Adam means is that if a binary element is less than a certain size then the overhead of using MTOM is not worth-while since you may come up with a longer message.

Sandeep said...

Another scenario where using MTOM with soap web services makes sense is that it allows large amount of data to be sent from the client (upload) or server (download). See sample code for SOAP and MTOM

Steve Djajasaputra said...

Nice comparison, please also see:
http://soa-java.blogspot.nl/2012/09/mtom-email-attachment.html