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”

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

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.
Before

After


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
Vital