Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
Serialization in DotNet

Serialization in DotNet

Ratings: (0)|Views: 1|Likes:
Published by Khaled Salahul Den

More info:

Published by: Khaled Salahul Den on Jun 21, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

06/21/2012

pdf

text

original

 
Serialization in DotNet
 
Serialization
is the Process of objects getting transformed to stream of bytes to be stored in aFile, Memory or a Database. The Main Purpose of Serialization is to Save the State of the objectin order to recreate it when needed. The reverse of this Process is called as
De-Serialization
.
 
Serialization
as said before stores the state of the object in Stream of bytes which can be storedin a File, Database or in Memory.Using which a developer can easily recreate the same instance of the object with all itsproperties whenever required.
 Different Serialization Formats
A.
 
Binary Format:
Binary formatter is the most efficient way to serialize objects thatwill only be read by .NET framework-based applications. This formatter class is in theSystem.Runtime.Serialization.Formatters.Binary
 
B.
 
Soap Format :
This XML Based formatter is easily read by .NET and non-.NETframework based applications .
 
A) Working sample of Binary Formatter :
 
1) You need to write the Serializable Class
 <Serializable()> _ 
Class
SerializeObjects DimnameAs String  Public PropertyEmpName()As String  Get ReturnnameEnd Get  Set(ByValvalueAs String) name = valueEnd Set  End Property 
End
 Class 
2) Now The class in which the Serialization will take place
 
Imports
System.IO 
Imports
System.Runtime.Serialization.Formatters.Binary 
Class
BinaryExample Shared SubMain()
 
 DimserAs NewSerializeObjects ser.EmpName ="Hefin" DimbinForAs NewBinaryFormatter() binFor.Serialize(File.Create("Demo.bin"), ser)End Sub 
End
Class 
B) Working sample of the SOAP formatter
 
The Serializable class remains the same only thing that changes is the class where theserialization will take place.
 
NOTE : A reference to the Namespace
System.Runtime.Serialization.Formatters.Soap
needs tobe added.
 
Imports
System.IO 
Imports
System.Runtime.Serialization.Formatters.Soap 
Class
SoapExample Shared SubMain() DimserAs NewSerializeObjects ser.EmpName ="Hefin" DimsoapForAs NewSoapFormatter() soapFor.Serialize(File.Create("Demo.xml"), ser)End Sub 
End
Class 
De-Serialization :-
The reverse of the serialization process is called the De-Serialization .
 
De-Serialization of the SOAP Serialized Object
 
Imports
System.IO 
Imports
System.Runtime.Serialization.Formatters.Soap 
Class
SoapExample Shared SubMain() DimserAs NewSerializeObjects DimsoapForAs NewSoapFormatter()
 
ser = soapFor.Deserialize(File.Open("Demo.xml", FileMode.Open))Console.WriteLine(ser.EmpName)End Sub 
End
Class 
De-Serialization of the Binary Serialized Object
 
Imports
System.IO 
Imports
System.Runtime.Serialization.Formatters.Binary 
Class
BinaryExample Shared SubMain() DimserAs NewSerializeObjects DimbinForAs NewBinaryFormatter() ser = binFor.Deserialize(File.Open("Demo.xml", FileMode.Open))Console.WriteLine(ser.EmpName)End Sub 
End
Class 
SerializationXML Serialization
 
Object Serialization is a process through which an object's state is transformed into someserial data format, such as XML or binary format, in order to be stored for some later use.In other words, the object is "dehydrated" and put away until we need to use it again.
 
Some good uses for serialization/deserialization include:
1.
 
Storing user preferences in an object.
 2.
 
Maintaining security information across pages and applications.
 3.
 
Modification of XML documents without using the DOM.
 4.
 
Passing an object from on application to another.
 5.
 
Passing an object from one domain to another.
 6.
 
Passing an object through a firewall as an XML string.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->