WCF MTOM Binary Data Transmission

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric




SOAP in general supports opaque data as content through the use of either base64 or hexadecimal text encoding. Both these techniques influence the size of the data. For example UTF-8 underlying text encoding and base64 encoding increases the size of the binary data by a factor of 1.33. Hexadecimal encoding expands data by a factor of 2. If  UTF-16 text encoding is used these factors will be doubled.

The Abstract SOAP Transmission Optimization Feature enables SOAP bindings to optimize the transmission and/or wire format of a SOAP message by selectively encoding portions of the message, whilst still presenting an XML Infoset to the SOAP application. Optimization is available only for element content that is in a canonical lexical representation of the xs:base64Binary data type.

Because there is a one-to-one correspondence between such canonical forms and values in the value space of xs:base64Binary, MTOM implementations typically optimize by transmitting a compact representation of the value in place of the less compact character sequence. At the receiver, the character form can be reconstructed if necessary.

My idea was to compare different WCF message formatters in comparison to MTOM. The results shown in this post can give you a feeling about amount of data transmitted over the wire.

Following table shows results:


byte[x] is the size of binary type Data. Text, Dictionary, Binary and Mtom are corresponding message formatters. As you see for very small number of binary bytes, there is no difference between formatters.

Here is an example of the MTOM message with Data[10]:


However, with increasing size of the property Data, MTOM starts to format the message as MIME package:


The size of 256 bytes used in example shown at the picture above is exactly the size which produce wars results by MTOM formatter. This means that MTOM is not always the best formatter. In most cases the binary formatter is the best one. However with inceasing of the size of binary data in the message the MTOM formatter convergences to the performance of the binary formatter. In my result table I shown the comparison till 5E5 bytes. In the real live I tested much higher values and noted that binary  and MTOM formatters show almost the same results.
Text and Dictionary formatters should definitely not be used for formatting of messages which contain binary data. 

This is the data contract which has been serialized in my example:


This is the code which has been used to produce results:



Posted Feb 02 2008, 11:45 PM by Damir Dobric
Filed under:


Lanier wrote re: WCF MTOM Binary Data Transmission
on 02-22-2008 16:59


Optimization is available only for element content that is in a canonical lexical representation of the xs:base64Binary data type.


What exactly does that mean? That the data has to be divisible by 64 bits?  Explain

Gaye wrote re: WCF MTOM Binary Data Transmission
on 06-05-2012 11:25

This has made my day. I wish all psoitgns were this good.

developers.de is a .Net Community Blog powered by daenet GmbH.