Binary and XML Serialization

   

The first time I heard the word serialization, I walked in the other direction. Why they give some software technologies seemingly complicated names is beyond me, but as you work through this hour, you'll notice that the basic mechanisms behind serialization in the .NET Framework are not too complicated at all.

The first question you have to ask yourself is why you would need or want to use serialization in the first place. The first reason, as just mentioned, is to save the state of an object. If you look through parts of your Registry, especially through the HKEY_LOCAL_MACHINE\Software section, you might run into a few applications that save information such as recently used files, the window size of the application when it was closed last, and other bits of state information. If that information is not contained within the Registry, it may be written to an INI file or other custom-designed file format. Rather than having to go through the somewhat manual and complicated process of saving Registry values or performing file input and output (I/O), the developer could instead have chosen to use serialization. A serialized class within the .NET Framework can have all its member variables, whether public or private, converted into a binary format and streamed onto a storage medium. The process of then taking the file that results from the serialization process and reconstructing the original managed class is known as deserialization.

Another way to use serialization which you may have used without knowing it is to transfer an object across process or machine boundaries. In other words, the object state is saved and converted to a form that can then easily be transferred to another application domain to be reconstructed at that destination point.

The .NET Framework supports two types of serialization: binary serialization and XML serialization. Binary serialization is best used to preserve the state of an object onto a storage medium. When an object undergoes binary serialization, all its public and private members are streamed in binary form into a file on the specified storage medium. The object can then be deserialized and subsequently reconstructed to be an exact copy of the original object later.

The other type of serialization is XML serialization. Unlike binary serialization, which preserves type information, XML serialization does not preserve type fidelity. For instance, if a member variable is an Int16 data type, the type of that member variable will be lost. Also, XML serialization will only serialize the public members of an object, as compared to binary serialization, which serializes both public and private data members. With these differences, you can see that XML serialization is best suited for transferring objects across platform boundaries using well-known protocols, such as the Hypertext Transfer Protocol (HTTP).

For the lesson this hour, you will be creating a managed C++ application that preserves state information for a Windows Form. Serialization will be handled using binary serialization, which saves the state information for a managed object onto the hard disk.


   
Top


Sams Teach Yourself Visual C++. NET in 24 Hours
Sams Teach Yourself Visual C++.NET in 24 Hours
ISBN: 0672323230
EAN: 2147483647
Year: 2002
Pages: 237

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net