XML and ASP.NET

only for RuBoard

The Microsoft .NET Framework provides an almost bewildering variety of ways to serialize an object. This chapter focuses on XML serialization, but before we get into the details, I'd like to briefly examine and compare the various serialization methods offered .

XML Serialization

XML serialization allows the public properties and fields of an object to be reduced to an XML document that describes the publicly visible state of the object. This method serializes only public properties and fields ”private data will not be persisted , so XML serialization does not provide full fidelity with the original object in all cases. However, because the persistence format is XML, the data being saved can be read and manipulated in a variety of ways and on multiple platforms.

The benefits of XML serialization include the following:

The restrictions of XML serialization include the following:

SOAP Serialization

SOAP serialization is similar to XML serialization in that the objects being serialized are persisted as XML. The similarity, however, ends there. The classes used for SOAP serialization reside in the System.Runtime.Serialization namespace rather than the System.Xml.Serialization namespace used by XML serialization. The run-time serialization classes (which include both the SoapFormatter and the BinaryFormatter classes) use a completely different mechanism for serialization than the XmlSerializer class.

The benefits of SOAP serialization include the following:

The restrictions of SOAP serialization include the following:

Binary Serialization

Binary serialization allows the serialization of an object into a binary stream, and restoration from a binary stream into an object. This method can be faster than XML serialization, and the binary representation is usually much more compact than an XML representation. However, this performance comes at the cost of cross-platform compatibility and human readability.

The benefits of binary serialization include the following:

The restrictions of binary serialization include the following:

Other Forms of Serialization

A number of other forms of serialization are available in the .NET Framework that are either not intended to be used directly or are specific to a problem domain, which is outside the scope of this book. These other serialization methods include the LosFormatter , which is used to serialize and deserialize page view state in ASP.NET, the CodeDomSerializer , which is used to serialize an object graph representing dynamically generated source code, the binary serialization used in .NET Remoting, and others.

only for RuBoard

Категории