The WCF MessageEncoder Decoded 2
Sample Overview
The sample opens an XML file using the XmlDocument class, translates the XmlDocument into bytes, creates a Message class from the bytes, and then copies the Message class back into another XmlDocument class.
There are some things to consider before you explore the sample.
Aside from illustrating the steps to take building your own MessageEncoder, the sample provides no real practical solution.
Normally, the MessageEncode is embedded inside of a WCF. As stated earlier, normally a MessageEncoder inhabits a Transport Channel class.
Finally, there are many ways to manipulate the bytes coming over the wire and to coerce the data into a Message class. Covering all tools and options is beyond the scope this article, so I’m going to review some of these tools with you before delving into the code.
Tools of the Trade
Manipulating XML data is the realm of the XmlReader and XmlWriter classes. XmlReaders and XmlWriters support all sorts of functionality including:
* A separate settings class for checking conformance, including whitespace, and specifying a particular encoding
* Reading, Writing, and efficiently navigating XML
* Reading XML from Stream classes
XmlDictionalReader and XmlDictionaryWriter classes serve to generate XmlReaders and XmlWriters specifically supporting new features in WCF.
XslCompiledTransformation is a new .NET 2.0 implementation of the .NET Extensible Stylesheet Language Transformation (XSLT) transformations functionality. XSLT serves to transformation a particular XML document into some other representation.
MessageEncoders can work with large amounts of data. Allocating space for large pieces of data can create a bottleneck in an application. So, WCF utilizes a class called MessageBuffer to control and manage pre-allocated memory pools.
MessageEncoders work with .NET Streams. Streams are classes that manipulate a series of bytes residing inside various places (file system, memory, network). All streams have a common base class along with functions specific to their area of specialization.
For more details, see the .NET Framework documentation and the articles listed under Sources at the end of this article.
It’s time to delve into the sample and put the tools above to use.
Tags: MessageEncode, MessageEncoders, xml, xslt

May 19th, 2008 at 12:38 am
[…] is the base class for all MessageEncoders. MessageEncoder contains overridable versions of the overloaded ReadMessage and WriteMessage functions. Which […]