Hi friends,
Ques : I want to know that what is a serialization in a .NET. Please explain in brief?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Mar 21, 2012, 12:58 PM
The serialization is converting an object type into stream of bytes.
There are several types of serialization.
1) Binary serialization
2) Soap serialization
3) XML serialization
4) Custom serialization
I suggest you to go through this url for examples
http://www.codeguru.com/csharp/.net/net_framework/article.php/c19541/
http://aspalliance.com/983_Introducing_Serialization_in_NET
Satyapriya NayakPosted Mar 21, 2012, 2:26 AM
Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes. Serialization/Deserialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database).Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.
Binary serialization preserves type fidelity, which is useful for preserving the state of an object between different invocations of an application. For example, you can share an object between different applications by serializing it to the clipboard. You can serialize an object to a stream, disk, memory, over the network, and so forth. Remoting uses serialization to pass objects "by value" from one computer or application domain to another.
XML serialization serializes only public properties and fields and does not preserve type fidelity. This is useful when you want to provide or consume data without restricting the application that uses the data. Because XML is an open standard, it is an attractive choice for sharing data across the Web. SOAP is an open standard, which makes it an attractive choice.
There are two separate mechanisms provided by the .NET class library - XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting.
Thanks
Prasant JinagaPosted Mar 21, 2012, 2:19 AM
Serialization is a process of taking an object and converting into a form so that it can be transported across the network or can be persisted in the storage location. This storage location can be physical file, database or ASP.NETCache. The form contains the state of the object so that by this format, we can construct the same object a later point in time, which is called Deserialization.
There are three formats of serialization
Binary Serialization : Light and compact used in Remoting
SOAP Serialization : interoperable use SOAP and used in web Services
XML Serialization : Custom Serialization
How Do You Use Serialization?
Serialization is handled primarily by classes and interfaces in the System.Runtime.Serialization namespace. To serialize an object, you need to create two things:
a stream to contain the serialized objects
a formatter to serialize the objects into the stream
The code required to perform serialization in .NET is very simple. Most serialization code is similar to the boilerplate code shown below, which serializes an object into a file stream using the BinaryFormatter class:
public static void WriteToFile(BaseballPlayer bp, String filename)
{
Stream str = File.OpenWrite(filename);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(str, bp);
str.Close();
}
Hope it helps!!!
Thanks,
Prasant