Introducing Serialization in .NET
page 5 of 14
by Joydip Kanjilal
Feedback
Average Rating: 
Views (Total / Last 10 Days): 84346/ 175

Types of Serialization

Serialization can be of the following types:

·         Binary Serialization

·         SOAP Serialization

·         XML Serialization

·         Custom Serialization

All these types of serialization are explained in details in the sections that follow.

Binary Serialization

Binary serialization is a mechanism which writes the data to the output stream such that it can be used to re-construct the object automatically.  The term binary in its name implies that the necessary information that is required to create an exact binary copy of the object is saved onto the storage media.  A notable difference between Binary serialization and XML serialization is that Binary serialization preserves instance identity while XML serialization does not.  In other words, in Binary serialization the entire object state is saved while in XML serialization only some of the object data is saved.  Binary serialization can handle graphs with multiple references to the same object; XML serialization will turn each reference into a reference to a unique object.  The following code listing shows how we can implement binary serialization.

Listing 2:

public void BinarySerialize(string filename, Employee emp)
{
  FileStream fileStreamObject;
  try
  {
    fileStreamObject = new FileStream(filename, FileMode.Create);
    BinaryFormatter binaryFormatter = new BinaryFormatter();
    binaryFormatter.Serialize(fileStreamObject, emp);
  }
  finally
  {
    fileStreamObject.Close();
  }
}

The following code listing shows how we can implement binary de-serialization.

Listing 3:

public static object BinaryDeserialize(string filename)
{
  FileStream fileStreamObject;
 
  try
  {
    fileStreamObject = new FileStream(filename, FileMode.Open);
    BinaryFormatter binaryFormatter = new BinaryFormatter();
    return (binaryFormatter.Deserialize(fileStreamObject));
  }
  finally
  {
    fileStreamObject.Close();
  }
}

View Entire Article

User Comments

Title: Really Very Good, and easy to understand Article   
Name: Ved Prakash
Date: 2006-12-29 6:24:11 AM
Comment:
Really Very Good, and easy to understand Article
Title: EASY TO UNDERSTAND   
Name: RESHMA
Date: 2006-12-27 7:30:09 AM
Comment:
EASY TO UNDERSTAND THE DIFFERENCES BETWEEN DIIF TYPE OF SERIALIZATIONS.
Title: Good Article   
Name: santosh
Date: 2006-12-08 1:50:03 AM
Comment:
Very nice one for those who doen't have much idea about serilazation. Basiaclly it is giving fair introduction.
Title: Good. Need Help   
Name: Nandhini.S
Date: 2006-11-10 6:21:53 AM
Comment:
Hi
This is very good for the starters to begin serialization. But im having doubt in Hoe to store a comple Windows ,Form object in XML document to reconstruct later.
Title: Fabulous! Good job   
Name: Mohammed Abrar
Date: 2006-11-07 2:07:16 AM
Comment:
This is a fantastic article about Serialization.
Special thanks to the author Joydip Kanjilal
Title: Excellent!   
Name: Peter Royle
Date: 2006-10-17 5:51:07 AM
Comment:
The best article I've seen for someone who knows nothing about serialisation (sic).
Title: Great Yaar   
Name: Rangarajan
Date: 2006-10-11 7:28:52 AM
Comment:
Great explanation.. Simple and subtle, understandable and staright forward..
Title: Thank you for your contribution!   
Name: Mamiow
Date: 2006-10-11 12:30:50 AM
Comment:
Very good and understanding article.
Title: best of one   
Name: Mukesh
Date: 2006-10-09 11:24:54 AM
Comment:
Very nice article....

Thanks
Title: What about Performance   
Name: Satyadev Singh
Date: 2006-10-09 3:22:28 AM
Comment:
Hi, This is really a excellent article, however I have some concern regarding the CPU performance when we are going to use SOAP formatter, because in my previous project I used Binary formatter and got CPU uses increased.
That's why I am scared about the CPU performance because in that particuler apps will have 1 hit per second.

You can reach me at singhsatyadev[*at*]gmail[#dot#]com


Thanks,
Title: Nice Article   
Name: ArunKumar P
Date: 2006-10-09 3:02:15 AM
Comment:
It is useful for Beginner's
Title: GIS Architect   
Name: Naren Ranganathan
Date: 2006-10-07 6:48:58 PM
Comment:
Great article on Serialization for newbies.
Title: Diff bet SOAP Formatter & Binary Formatter & XML Formatter   
Name: Jitendra C
Date: 2006-10-03 7:27:51 AM
Comment:
Great!It gives a broad picture of Serialization.I wanted to know more on Difference between SOAP Formatter & Binary Formatter & XML Formatter
Title: need details   
Name: Haroon
Date: 2006-09-29 1:46:27 AM
Comment:
this article is good. but what if we want to know that which .net types (e.g SQL types for .net like SQLBoolean and e.t.c.., that are not serializable) are serializable.
I would appreciate if you can provide list of the types that are not serializable in .net
Title: Good for starters   
Name: Sandeep Gulati
Date: 2006-09-25 1:55:25 PM
Comment:
A good articles for starters.
Title: gr8 article   
Name: abhi_viking
Date: 2006-09-25 7:29:02 AM
Comment:
really useful 1
Title: Very useful   
Name: BT
Date: 2006-09-23 11:29:27 PM
Comment:
Very nice article but I'm still left to wonder which of the serilization methods described above is the best one to use (most widely used in the field).
Title: Simple but most Effective   
Name: Mazher Yasin
Date: 2006-09-21 2:15:44 AM
Comment:
Greate Effort
Title: Superb   
Name: Amin
Date: 2006-09-13 2:58:59 PM
Comment:
10 out of 10
Title: Very Good Introduction   
Name: Bharat Sisodiya
Date: 2006-09-12 8:20:29 AM
Comment:
Very good Information for Starters
Title: Great Article   
Name: Michelle
Date: 2006-09-06 3:53:20 PM
Comment:
Great article - good information!






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2022 ASPAlliance.com  |  Page Processed at 2022-09-27 2:38:20 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search