WCF # 18–WCF Serialization Vs Encoding [XML Information Set,Difference between XML infoset and XML]
Today we will start with very interesting feature of WCF called Serialization and Encoding.
We use serialization for transmission of messages in between client and server we need to convert CLR types to standards-based XML.
Encoding is the conversion of WCF message in to the byte array.
Serialization Vs. Encoding
There are important differences between serialization and encoding in WCF.
-> It is the term often used to describe the process of converting an object graph into an array of bytes.
-> This is a very useful feature for representing the state of an object. Serialization can be used to persist an object’s state to a file or a database, copy an object to the clipboard, or transfer objects across a network to another application. WCF does not follow the standard definition of serialization, though.
-> WCF defines serialization as the process of converting an object graph into an XML Information Set (XML Infoset)
i) The XML Infoset is the data model WCF uses internally to represent a message.
ii) The XML Infoset is the data model for representing an XML document.
Difference between XML and XML Infoset
-> XML use only standard text format.XML Infoset doesnt have such restrictions.
WCF can represent messages in different formats as long as they are based on an XML Infoset. This includes the text format specified by the XML1.1 specification as well as other formats such as a binary XML format.
-> 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.
-> For example, you may want to use the BinaryMessageEncoder for optimal performance between .NET applications, use the TextMessageEncoder for interoperability based on WS-* Web services, or use the JSONMessageEncoder for AJAX-based Web applications.
In our coming posts we look at how WCF uses serialization and encoding to transmit messages across a transport. We will examine the different forms of serialization and encoding and present scenarios where each option should be used..