Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

What is serialization and different types of serialization in ASP.NET

Author: Mike Green

I will explain serialization, deserialization and different types of serialization in this article.

 

 

Serialization
 
Serialization is the process of converting object data into a format that can be stored or transmitted through a network. In serialization process, the object is converted into stream of data to store in a location or to transfer to other location using network. The storage location can be a file or database table or cache. Using serialization for objects has some reasons, first is to get the same copy of data to use it and second is to transfer data from one application to another easily. The process of serializing objects is also called marshaling or deflating. Marshaling actually used data is needed to transfer between different parts of a program or from one part of program to other part of a different program. So serialization and marshaling are similar.
 
Deserialization
 
When we reverse the process of serialization, it is called deserialization. It is to reconstruct the same object from serialized data. Deserialization means to reconstruct the stored or transmitted data into an original object. Demarshaling is similar to deserialization.
 
Types of Serialization
 
The basic purpose of serialization is to convert data into a format that can be stored or transmitted through a network. The data should be in a format that can be read and understood by sender and receiver in a communication of the data.
 
Serialization has following three types to convert data into different formats.
 
Binary Serialization
XML Serialization
SOAP Serialization
 
Binary Serialization
 
Binary serialization is to convert objects into binary information. In binary serialization, name of the class, assembly and public and private fields of objects are converted to stream of bytes which is then written to data stream. The entire object data is saved using binary serialization and it also saves identity of the instance. Type information is also not lost in the binary serialization. It preserver type information so that when deserialization process will be done, the object of the same type or same class will be reconstructed. Binary serialization is faster and efficient way of serialization than other serialization types. It also ensures that serialized objects are in a much more compact representation than any other serialization. To implement binary serialization, the class must have to implement ISerializable interface or it must be marked with Serializable Attribute.
 
BinaryFormatter
 
BinaryFormater class is used in ASP.NET for binary Serialization.
 
XML Serialization
 
XML serialization is to convert objects into XML information. It only convert public properties of objects into XML and it does convert private fields of that object so XML serialization does not provide full serialization. XML Serialized data does not contain class name and assembly. It is also called shallow serialization. XML serialization is much slower than binary serialization. XML Serialization has some advantages also over other serialization types. As the XML is an open standard so the data converted into XML can be processed on any platform by any application. It can serialize generic and non-generic collections. XML format is a format that is readable by both machine and human.
 
XMLSerializer
 
XMLSerializer class is used to serialize and deserilize objects
 
SOAP Serialization
 
SOAP is a protocol based on XML so SOAP Serialization is similar to XML Serialization in a way that objects are persevered as XML format. It is, however, not similar to XML serialization as SOAP Serialization produces SOAP messages which can be transferred on any platform. It is actually used when portability is required. The word Serializable is used before the class in SOAP serialization to serialize objects. It is different from XML Serialization also because it converts all object including class name, assembly information and public and private fields. It cannot serialize generic collections. SOAP Serialization is less fast and less efficient than binary serialization. SOAP Serialization can be easily converted to binary serialization.
 
SOAPFormatter
 
SOAPFormatter is used for SOAP Serialization and it converts objects into SOAP messages.
 
Custom Serialization
 
Custom serialization is referred to as a serialization of a type. It is actually controlling serialization and deserialization of a type. This approach is provided for developers so that they can take full control on serialization according to their own needs. Custom Serialization is achieved by implementing ISerializable interface on an object. This interface implements an overloaded constructor and GetObjectData() method. 

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to use AJAX TabContainer Control in ASP.NET

Disclaimer - Privacy
© 2002-2017 DevASP.net