Wednesday, May 18, 2011

Transfer large messages in WCF - Part 2

This is in continuation with Part 1. let us look into details of Message Transmission Optimization Mechanism (MTOM)

Enable MTOM for above service by setting messageEncoding = “Mtom”

  <binding messageEncoding="Mtom" name="largeObjects" maxReceivedMessageSize = "6500000" ></binding>

When we try to upload our file the bytes are converted into Base 64 encoded data in SOAP envelope.

By enabling MTOM, SOAP messages are sent as Mulitpurpose Internet Mail Extension (MIME) multipart/related content.

Here, data will not be encoded any more thus reducing processing overhead of encoding and decoding into Base 64. Another disadvantage with base 64 encoded data is that it increases the data size by approximately 33%. So by enabling MTOM we will gain this 33% size as well.

You can visualize the difference using fiddler.


MTOM helps in improving transfer overhead and processing performance. But the entire message is still loaded into memory. Let us try to visualize this using windows task manager.

When I tried to upload a file of size 88 MB, client will load all Binary data(MTOM)/Base 64 data(Text) to memory. Once it completely loads data, the service will start receiving it and we can observe memory consumption in task manager. The client continuously increases memory consumption for our scenario till it goes up to 450 MB and then the memory consumption in service starts increasing. See below screen shot

We will see how we can improve this in the next part

Hope this helps


  1. hi Vital
    nice one more thing is while we are planning to send large data(> 1MB) with secure mode with streamming the data.

  2. i'm planning to address streaming in next part

  3. vittal, plz try to explain different Tranfermodes and Timeout issues in u r next articles..we will try to support if u need any help on this.

  4. Thanks for your suggestion.
    In next article i will post on streaming where i will address different transfer modes.
    After Streaming i will try to write something on timeout issues

  5. Very good Posting.please continue sending article links. One small sugesstion here is please share the links in Facebook so that it would have more visibility to all.

  6. Very Nice Article...Please provide some detail article on Callback Contract...

  7. Thanks Akhil! I have written some article on pub/sub which uses callback contract. Please have a look into it