SOAP with Attachments using MTOM

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.

  1. base64 encoding data takes time.
  2. base64 encoding data increases its size by 33%.
  3. 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:

xop:Include href="cid:0123456789"xmlns:xop="http://www.w3.org/2004/08/xop/include"

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--
Advertisements

About Arpit kulshrestha

Arpit K Kulshrestha Graduated in Computer Science with HONORS Degree in 2012. He is on mission to develop or to be a part of great mobile application which can enhance user experience and able to explore the world. 6 + Years of Apple Mobile Application Development Experience with a strong focus on Building Enterprise, Social Networking Applications and working with Objective-C, Xcode, Storyboard & Instruments. Working knowledge of Core iOS frameworks and skilled in debugging. He has developed apps using SOAP, REST, JSON and XML based Web Services. He is interested to pursue a career in Mobile Applications Development field and he is certain that his skills and work experience prepared him well for such role.
 He has been a specialist in Multimedia & Networking based iOS applications in these years. Have a good in depth knowledge in Network Programming models like TCP/IP. Have done several rich multimedia (Videos & Images) processing & manipulating applications in the same. 
He is accustomed to successfully juggling multiple projects and have an excellent track record of forging strong relationships with client. He work equally well in team-oriented and self-directed environments and find the challenges of the start-up setting stimulating. Specialties:- Map kit , Core Location , UIKit , Core Data , SQLite , Google API's , Facebook API's ,Cocoa 2D, Core Motion, Event Kit.
This entry was posted in Uncategorized. Bookmark the permalink.

1 Response to SOAP with Attachments using MTOM

  1. varun karhadkar says:

    Hello, I am trying to send video file using MTOM can you tell me how to generate request for that, And is there any library available to this as I want to upload video from mobile app.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s