A .NET object can be serialized with different types of
encodings. Let us discuss some of the serializations in detail.
·
Binary Serialization – The encoding used for this type of
serialization is binary encoding. Using this serialization when an object is
serialized, all the public and private fields are serialized. This means that
the exact binary copy of the object is replicated. This brings about the concept
of cloning an object (using binary serialization we can clone an object). One
of the major advantages of Binary Serialization is the performance. The
serialization and de-serialization cost would be minimal. However, binary
serialization is not easily portable especially with cross platforms.
·
XML Serialization – XML Serialization serializes only the public
properties and does not bother the private variables. It is to be noted that
the type fidelity is also not preserved. When using XML serialization we cannot
guarantee the original state of the objects. The primary purpose of the XML
serialization would be conversion of XML documents into .NET objects and .NET
objects into XML documents. In spite of having many issues with XML
serialization, the main reason it is used is because of its support over cross platforms. In .NET 2.0, the XmlSerializer class takes care of the
serialization. It has 2 methods, Serialize and DeSerialize, for serializing and
de-serializing.
·
SOAP Serialization – SOAP serialization is a special form of XML
serialization, but conforms to the SOAP specification. SOAP is a protocol based
on XML designed for transporting method calls over the web. The .NET Framework supports the serialization that conforms to the SOAP standards. We can use the XmlSerializer
class that can serialize classes in SOAP standards. SOAP is an example of
custom serialization. We will see more about basic and custom serialization in
the next sections.
·
Designer Serialization – Designer serialization is a special form
of serialization which involves object persistence usually associated with
development tools. Designer serialization is generally used in cases of
displaying graphs, designer tools, etc. The designer shown in Visual studio is
a type pf designer serialization. The emphasis on the designer serialization
will be on the object's exact state with respect to other objects visually. It
will always help if the designer serialization format is in a human readable
format.