The WCF MessageEncoder Decoded 3
Class Requirements
Like Channels and other classes in WCF, when you build a MessageEncoder you also build an accompanying MessageEncodingBindingElement and MessageEncoderFactory. Also, as with other WCF classes, the binding class handles configuration and the factory class handles creation. Following is the class declaration for TestEncoderFactory.
public class TestEncoderFactory : MessageEncoderFactory
{
Following is the class declaration for TestEncoderBinding.
public class TestEncoderBindingElement :
MessageEncodingBindingElement
{
As stated earlier, normally the MessageEncoder resides inside the Transport Channel. My WCF Channels and Binding article illustrates how to incorporate a MessageEncoder in the binding and use a MessageEncoder inside a Transport Channel. Typically, the MessageEncoder is created by using the following function calls and properties.
TestEncoderBindingElement elm = new TestEncoderBindingElement(); TestEncoderFactory factory = new TestEncoderFactory(elm); RunProgram prog = new RunProgram(); .. prog.Run(factory.Encoder);
MessageEncoder is the base class for all MessageEncoders. MessageEncoder contains overridable versions of the overloaded ReadMessage and WriteMessage functions. Which functions you invoke depend on which style of Message you wish to create; see the Sources section at the end of the article for more information on Messages. You’ll see how to implement a few ReadMessage and WriteMessage functions later in the article.
There are also some important overridable properties and functions dealing with the “body” or data portion of a Message class. ContentType, MediaType, and MessageVersion are the key properties. The importance of other functions depends on your implementation of the class.
As stated earlier, a MessageEncoder turns bytes on the wire to Message class. Look at how this is done.
previous entries about message encoder; 1 and 2 and here 3
Tags: message encode, MessageEncoder
