.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Binary Serialization in .net

Posted By:Asha.MP       Posted Date: November 22, 2010    Points: 50    Category: ASP.NET    URL: http://www.dotnetspark.com  

Serialization is the process of formatting the data to tranfer from one application/system to other application/system through network. There are two types of serialization, first one is binary and second one is Soap formatting. In this article i will explain how to make use of binary Formatter in the serilzation process.
 

During serialization there are 4 steps(SrcCode-1)

1.Creat the stream object with the create mode (filestream in below code)

2.Create the object of binary formatter(bf in below code)

3.Call serialize function by using binary formatter object(bf) with the two arguments as filestream object and the data to be serialize.

4.Close the filestream object

During Desearization (SrcCode-2)

1.Creat the stream object with the open mode (filestream in below code)

2.Create the object of binary formatter(bf in below code)

3.Call Deserialize function by using binary formatter object(bf) with the an arguments filestream object. you can save returned object in the object or directly you can display that returned object using console.writeline.

4.Close the filestream object

'Serialization using binary formatter(SrcCode-1) Option Strict On Option Explicit On Imports System.IO Imports System.Runtime.Serialization.Formatters.Binary Public Class BinarySerializObj Public Shared Sub main() 'Reading the text from user Console.WriteLine("Enter text to be serialized") 'Saving it in the string variable Dim str As String = Console.ReadLine() 'creating new instance of Filestream in the Create mode of the file Dim fileStream as New FileStream("E:\SerData.data",FileMode.Create) 'BinaryFormatter object Dim bf As New BinaryFormatter() 'Calling serialize function using binary formatter object bf.Serialize(fileStream, str) 'Closing the file stream object fileStream.Close() End Sub End Class 'Deserialization process using binary formatter(SrcCode-2) Option Strict On Option Explicit On Imports System.IO Imports System.Runtime.Serialization.Formatters.Binary Public Class BinarySerializObj

Public Shared Sub main() 'creating new instance of Filestream in the open mode of the file Dim fileStream As New FileStream("E:\SerData.data", FileMode.Open) 'BinaryFormatter object Dim bf As New BinaryFormatter() 'Calling serialize function using binary formatter object Console.WriteLine("Text after deserialization") 'Callind deserialize method using the binary formatter object Console.WriteLine(bf.Deserialize(fileStream)) 'Closing the file stream object fileStream.Close() Console.ReadLine() End Sub End Class

 

 

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend