Tips to Optimize Transmission of Binary Data Using MTOM/XOP
If you are looking for a simple and better technique to transfer huge files over a web service, then this post could guide you. In this technical blog, we will discuss how Message Transmission Optimization Mechanism (MTOM) can be used to optimize binary data transfer. MTOM allows you to efficiently transmit large binary data to avoid memory problems.
SOAP Message Transmission Optimization Mechanism (MTOM) and XML-binary Optimized Packaging (XOP), together referred as MTOM/XOP defines a method for optimizing the transmission of XML data of type xs:base64Binary in SOAP messages.
When the transport protocol is HTTP (Hypertext Transfer Protocol), MIME (Multipurpose Internet Mail Extension) attachments are used to carry the above mentioned type of data. While transferring the data, both the sender and the receiver are allowed direct access to the XML data in the SOAP message, without having to be aware that any MIME artefacts were used to marshal the base64Binary.
The binary data optimization process includes the following steps:
- Encode the binary data.
- Remove the binary data from the SOAP envelope.
- Compress the binary data.
- Attach the binary data to the MIME package.
- Add references to the MIME package in the SOAP envelope.
Once you complete the above five steps, the Request header should appear as shown below:
Serialization of a SOAP Message
XML serialization refers to the conversion of the public fields and properties of an object or the parameters, so that they return the values of methods into an XML stream, that adheres to a specific XML Schema definition language (XSD) document. Since a SOAP message is built using XML, serialization results in strongly typed classes with public properties and fields that are converted to a serial format. This facilitates efficient storage or transport of data.
Following conditions should be met for serialization of a SOAP message:
-
The content-type of the outer package MUST be multipart/related.
-
The type parameter of the content-type header of the outer package MUST have a value of application/xop+xml.
-
The start-info parameter of the content-type header of the outer package MUST specify a content-type for the root part of text/xml.
-
The content-type of the root part MUST be application/xop+xml.
-
The type parameter of the content-type header of the root part MUST specify a content-type of text/xml.
Sample SOAP with MTOM XOP Attachment
How XOP Works
XOP extracts binary data in an XML document, and serializes them into packages located inside an extensible packaging format, such as MIME Multipart/Related. The new XML document marks the locations of those binary data packages with special elements that contain URI identifying the corresponding location.
Unlike traditional approaches for handling binary data in XML documents, XOP does not require encoding binary data in base64. The data can take its original format as octet streams. An application parsing an XOP package may work directly with the octet stream, or if appropriate, compute the base64 binary character representation from this stream.
How MTOM identifies MTOM Message
MTOM provides a concrete implementation for using XOP, to optimize the transmission and/or wire format of SOAP messages. It describes how to serialize a SOAP envelope using the XOP format and MIME Multipart/Related packaging (note that MIME Multipart/Related is not required in XOP).
Following the rules specified, MTOM serializes a SOAP message into a MIME Multipart/Related XOP package with:
-
one body part (the root) that contains an XML representation of the modified SOAP envelope and,
-
additional parts that contain the binary representation of each element of the xs:base64Binary type.
With MTOM, deserialization of this transferred SOAP message follows the standard XOP approach. MTOM further specifies a concrete implementation of this mechanism for SOAP HTTP binding. For example, it requires placing the MIME headers of the resulting MIME Multipart/Related XOP package in HTTP headers and the rest of the package into the HTTP body.
You can identify MTOM in a SOAP message transmission over HTTP, by using the following four attributes:
-
The application/xop+xml media is present.
-
The media type of the HTTP message is multipart/related.
-
The media type of the root part of the MIME Multipart/Related package is application/xop+xml.
-
The start-info parameter indicates a content type of application/soap+xml.
In standard SOAP messages, binary objects are base64-encoded and are included in the message body. This increases their size, especially for very large binary objects, and affects the transmission time. By implementing MTOM/XOP, this issue can be solved.
If you find these tips useful, then let us know in the comments section of this blog. We would love to hear your feedbacks and suggestions.
Zerone develops bespoke software solutions carefully customized for the needs of our clients. Contact our experts today.
We can help!