Monday, 8 June 2015

MTOM in WCF - Sending large data in WCF


Let's discuss a scenario,suppose  you want to transfer a large amount of data like .doc file using WCF.

If size of data/file is more than 65546, you will get following error.
"The maximum message size quota for incoming messages(65536) has been exceeded".

Now the solution is to set maxReceivedMessageSize attribute in binding tag to resolve this.



The default message encoding in wcf is Text, which is base64 encodes data. this has the following 2 disadvantages.


  1. Base64 encoding increases the message size by approximately 33%.
  2. Involves additional processing overhead to base64 encode and decode.


To overcome with these disadvantages we have another approach to send large data using WCF.

The preferred approach to send large binary messages in WCF is to use MTOM message encoding.

Following configuration is needed in config file to implement MTOM.



MTOM is an interoperable standard and stand for "Message Transmission Optimization Mechanism".

MTOM does not use base64 encode data.This also means, the additional processing overhead to base64 encode and decode data is removed.hence, MTOM can significantly improve the overall message transfer performance.

With Text message encoding, the binary data is base64 encoded and it is embedded in SOAP envelop.
With MTOM, data is in binary form and this binary data is included as MIME attachment.

Related Topics : 
Message-exchange-pattern-in-wcf
Different-option-of-hosting-wcf-service
Binding-in-wcf-choosing-right-wcf-service
Hosting WCF with Non-Http protocol
Exchanging-metadata-in-wcf
Some-interesting-facts-about-data-contract
Knowntype-attribute-in-wcf
Associating-knowntype-in-wcf
Message-contract-in-wcf
Exception-handling-in-wcf
Exception Handling in WCF - SOAP Fault in WCF
Exception Handling in WCF - Unhandled Exception in WCF
Exception Handling in WCF - Creating and Throwing Strongly Typed SOAP Fault
Instance-context-mode-in-wcf




1 comment:

  1. share files I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.

    ReplyDelete