SOAP with Attachments – SwA (SOAP with Attachments) is a mechanism for using the existing SOAP and MIME facilities to perfect the transmission of files using Web Services invocations. SwA is a W3C Note. It was submitted as a proposal , but it was not adopted by W3C. Instead, MTOM is the W3C Recommendation for handling binary data in SOAP messages.
Problem Statement –
In case of Mobile Architecture (iOS and Android Apps) , OS plateforms trying to load the entire SOAP message into memory causing out of memory errors. So simple SOAP message without MTOM can create a lot problem in app development.
MTOM (Message Transmission Optimisation Mechanism) – MTOM uses the XML-binary Optimized Packaging (XOP) in the context of SOAP and Multipurpose Internet Mail Extensions (MIME) over HTTP. XOP defines a serialization mechanism for the XML Infoset with binary content that is not only applicable to SOAP and MIME packaging, but to any XML Infoset and any packaging mechanism. It is an alternate serialization of XML that happens to look like a MIME multipart or related package, with XML documents as the root part. MTOM is solution of following problems which occurs when sending a large amount of binary data.
- base64 encoding data takes time.
- base64 encoding data increases its size by 33%.
- Most SOAP implementations will try to load the entire SOAP message into memory causing out of memory errors.
When a SOAP message has an MTOM attachment, the binary data of the attachment is stored “below” the actual XML under a MIME header. This allows the SOAP message to be free of the burden of having to carry a very large string of base64 encoded data. But how do we get the binary data if it isn’t located in the XML itself? This is where XOP comes in. XOP is a method of referencing the binary data in your message from inside the SOAP XML envelope. When the server or client receives a SOAP message it needs to know where in the message the binary data is.
XOP (XML – binary Optimized Packaging) – Using XOP means that instances of XML-type base64Binary, if enabled, are transported by using MIME attachments. If XOP is in use, the implementation can automatically encode it. XOP maintains the data model of the XML message because the attachment is treated as base64-encoded data. If an XML stack understands XOP encoding, your application does not need to be changed at all.By looking at the XOP node we can find the binary data from the Content ID.looks something like this:
SOAP Message Format without MTOM – Without MTOM, the data is encoded in whatever format is described in the schema (base64 or hex) and then appears in the XML document. The following example shows a SOAP message with an <xsd:base64Binary> element.
... other transport headers ... Content-Type: text/xml; charset=UTF-8 <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header/> <soapenv:Body> <sendImage xmlns="http://org/apache/axis2/jaxws/sample/mtom"> <input> <imageData> R0lGODl ... more base64 encoded data ... KTJk8giAAA7 </imageData> </input> </sendImage> </soapenv:Body> </soapenv:Envelope>
SOAP Message Format with MTOM – When MTOM is enabled, the binary data that represents the attachment is included as a MIME attachment to the SOAP message. The following example shows an MTOM-enabled SOAP message with attachment data:
... other transport headers ... Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_0FE43E4D025F0BF3DC11582467646812; type="application/xop+xml"; start="<0.urn:uuid:0FE43E4D025F0BF3DC11582467646813@apache.org>"; start-info="text/xml"; charset=UTF-8 --MIMEBoundaryurn_uuid_0FE43E4D025F0BF3DC11582467646812 content-type: application/xop+xml; charset=UTF-8; type="text/xml"; content-transfer-encoding: binary content-id: <0.urn:uuid:0FE43E4D025F0BF3DC11582467646813@apache.org> <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header/> <soapenv:Body> <sendImage xmlns="http://org/apache/axis2/jaxws/sample/mtom"> <input> <imageData> <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:1.urn:uuid:0FE43E4D025F0BF3DC11582467646811@apache.org"/> </imageData> </input> </sendImage> </soapenv:Body> </soapenv:Envelope> --MIMEBoundaryurn_uuid_0FE43E4D025F0BF3DC11582467646812 content-type: text/plain content-transfer-encoding: binary content-id: <1.urn:uuid:0FE43E4D025F0BF3DC11582467646811@apache.org> ... binary data goes here ... --MIMEBoundaryurn_uuid_0FE43E4D025F0BF3DC11582467646812--