WCF # 21 # – WCF Encoder , Types of WCF Encoders , Choose Appropriate encoder
Hi Geeks,
Today We will see WCF Encoder ,their types and how to chose the appropriate encoder according to the situation.
-> First we will see what does Encoding mean in WCF ????
It is the term used to describe the process of converting a WCF message into an array of bytes. This is done so that the message can be sent across a transport protocol.
Note : Encoding is not something that you work with directly. Instead, it is specified by the binding used to expose a service.
For Ex In this example we have used
- <bindings>
- <basicHttpBinding>
- <binding name="testBinding"
- messageEncoding="Text">
- </binding>
- </basicHttpBinding>
- </bindings>
-> Types of WCF Encoders
WCF provides five types of encoding formats:
1.Binary
2.Text
3.Message Transmission Optimization Mechanism(MTOM )
4.JavaScript Object Notation
5.Plain Old XML (POX)
We will go in depth with first three types as those are used the most.
1.Binary Encoding
Binary encoding, the first thing to understand is that it is not a interoperable encoding. If your clients and service are all built with WCF then go ahead and use Binary Encoding.
Binary Encoding is great stuff if you are using Message level security. In message security 90% of the SOAP header is security!
the binary message encoder, uses a compact binary format and is optimized for WCF to WCF communication, and hence is not interoperable. This is also the most performant encoder of all the encoders WCF provides.
2.Text (DataContractSerializer)
The text message encoder, supports both plain XML encoding and SOAP encoding. The plain XML encoding mode of the text message encoder is called "plain old XML" (POX) to distinguish it from text-based SOAP encoding.
Text encoding was acceptable for ASP.NET Web Services because it allowed for interoperability across platforms. WCF abstracts out the encoding mechanism and
allows for bindings that allow for both styles of encoding. This allows WCF to provide functionality that replaces both .NET Remoting and ASP.NET Web Services.
The text encoder converts messages into text-based XML. This is great for interoperability.
3.Message Transmission Optimization Mechanism(MTOM )
The text encoder converts messages into text-based XML. This is great for interoperability, but it is not efficient at transmitting large chunks of binary data.
MTOM is used to send large amounts of binary data as raw bytes in interoperable scenarios.
As mentioned previously,MTOM refers to Message Transmission Optimization Mechanism.This is standard for optimizing the binary data by sending the binary data
- <bindings>
- <basicHttpBinding>
- <binding name="testBinding"
- messageEncoding="Mtom">
- </binding>
- </basicHttpBinding>
- </bindings>
4.JavaScript Object Notation
One of the emerging popular formats for sharing content online is JSON, shorthand for JavaScript Object Notation. Intended to be slightly more efficient than XML, it’s found a home in lots of AJAX powered web applications. Some companies actually require you talk to their APIs in terms of JSON too, so having the ability to parse and emit arbitrary JSON in a strongly typed way is a valuable tool to have. As of .NET 3.5 SP1, we are equipped with the DataContractJsonSerializer.
To know more on the WCF classes and for choosing appropriate encoder belonging to each type please visit WCF Encoders.
Thank You.
Hope this Will help you..
![]()