Skip to main content

Advantages and Disadvantages of MTOM and Streaming in WCF

Posted in

You can use MTOM and streaming to transfer large amounts of binary data in a WCF solution in an efficient way. The following table describes MTOM and streaming, and their suitability. For more information, see Large Data and Streaming.

MTOM
Data that is sent in a standard message over MTOM is sent and reconstructed in memory. The use of MTOM is largely transparent to the interface and the service implementation. This means that it places minimal restrictions on contract design and binding selection. However, because MTOM can use a lot of memory, it might be infeasible in some scenarios.

For relatively small binary data, MTOM will be more efficient because it lacks the setup overhead of streaming. It has the advantages of being interoperable, and supporting most bindings and security modes, but at the cost of memory usage and performance impacts. If you can split the data into multiple blocks, it is usually better to send it as multiple MTOM messages rather than using streaming. However, all of the data might not be available when the transfer starts; if this is the case, streaming is the only option.

Streaming
Streaming is an optimized transfer mechanism that links the source and destination for a direct transfer. There is no need to load large binary (or text) data into memory to send it across a WCF connection. Streaming starts transferring faster and has far less memory overhead. For truly large binary data, streaming will be faster and more efficient.

You probably want to have streaming operations on their own contracts to support alternative bindings that you configure specifically for streaming. It has the advantages of a low memory use and good performance, but it is WCF-specific, has interface restrictions, and is limited to the BasicHttpBinding, NetTcpBinding, and NetNamedPipeBinding bindings and transport-level security.