6
Reply

what is serialization in .net

vijay kumar

vijay kumar

10y
1.9k
0
Reply

    Serialization is the process off converting object into stream of bytes to store information of the object as well as its metadata so that bytes stream can later be converted back into object by using Deserialization. By serialization the data can be stored into database or send over the network.

    Serialization:1.Serialization is a process of converting an object into a stream of data so that it can be is easily transmittable over the network or can be continued in a persistent storage location. This storage location can be a physical file, database or ASP.NET Cache.2.Serialization is the technology that enables an object to be converted into a linear stream of data that can be easily passed across process boundaries and machines. This stream of data needs to be in a format that can be understood by both ends of a communication channel so that the object can be serialized and reconstructed easily.Advantage:Using serialization is the ability to transmit data across the network in a cross-platform-compatible format, as well as saving it in a persistent or non-persistent storage medium in a non-proprietary format.Serialization is used by Remoting, Web Services SOAP for transmitting data between a server and a client. The Remoting technology of .NET makes use of serialization to pass objects by value from one application domain to another.De-serialization is the reverse; it is the process of reconstructing the same object later.Types of SerializationSerialization can be of the following types:1.Binary Serialization2.SOAP Serialization3.XML SerializationBinary 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.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 objectSOAP Serialization:The SOAP protocol is ideal for communicating between applications that use heterogeneous architectures. In order to use SOAP serialization in .NET we have to add a reference to System.Runtime.Serialization.Formatters.Soap in the application. The basic advantage of SOAP serialization is portability. The SoapFormatter serializes objects into SOAP messages or parses SOAP messages and extracts serialized objects from the message. XML Serialization:· According to MSDN, "XML serialization converts (serializes) the public fields and properties of an object or the parameters and returns values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document.· XML serialization results in strongly typed classes with public properties and fields that are converted to a serial format (in this case, XML) for storage or transport. Because XML is an open standard, the XML stream can be processed by any application, as needed, regardless of platform." Implementing XML Serialization in .Net is quite simple.

    Passing Data Between Storages using Some Encryption techniques.Encrypting the Data into an Object and pass it Use Decrypt to convert the object into data

    Serialization is the process off converting object into stream of bytes to store information of the object as well as its metadata so that bytes stream can later be converted back into object by using Deserialization. By serialization the data can be stored into database or send over the network.

    object conversion in text stream is serialization and text stream conversion in object of a class is called deserialization

    Serialization is the process of converting an object to a stream. This is mostly done to save the state of the object to recreate and use it at a later time. Sample code: using System; using System.IO; using System.Xml.Serialization; class MainClass { static void Main() { // Creating a object to serialize. MyObject o = new MyObject(); Console.WriteLine("Object o created..."); Console.WriteLine(Environment.NewLine + "Now we will serialize it."); //Creating our XMLSerializer for our object type. XmlSerializer serializer = new XmlSerializer(typeof(MyObject)); //Creating a Stream to get the data to file. StreamWriter file = new StreamWriter(@"c:\temp\SerializedData.xml"); //Doing the deed, passing our file path and name as well as the object. serializer.Serialize(file, o); //Close the stream. file.Close(); Console.WriteLine(Environment.NewLine + "Serialization complete, go check the result."); Console.WriteLine(Environment.NewLine + "Press any key to exit."); Console.ReadKey(); } } public class MyObject { public int num = 42; public string oName = "Object Name"; public MyObject() { } }