Serialization is the process of saving the state of an
object in a persistent storage media by converting the object to a linear stream
of bytes. The object can be persisted to a file, a database or even in the memory.
The reverse process of serialization is known as de-serialization and enables us
to re-construct the object from the previously serialized instance of the same
in the persistent or non-persistent storage media.
Serialization in .NET is provided by the
System.Runtime.Serialization namespace. This namespace contains an interface
called IFormatter which in turn contains the methods Serialize and De-serialize
that can be used to save and load data to and from a stream. In order to
implement serialization in .NET, we basically require a stream and a formatter.
While the stream acts as a container for the serialized object(s), the
formatter is used to serialize these objects onto the stream.
The basic advantage of serialization is the ability of an
object to be serialized into a persistent or a non-persistent storage media and
then reconstructing the same object if required at a later point of time by
de-serializing the object. Remoting and Web Services depend heavily on
Serialization and De-serialization. Refer to the figure below.
The above figure illustrates that the serialized object is independent
of the storage media, i.e., it can be a database, a file or even the main
memory of the system.