Saturday, May 2, 2009

C# - System.Runtime.Serialization namespace


Serialization is the process of converting data into a byte stream that can be stored or transferred. The rule is to use BinarryFormatter for the best efficiency and SoapFormatter when you require portability, SoapFormatter provides less efficient but more interoperable rather than BinaryFormatter. There are two classes for formatting serialized data in the System.Runtime.Serialization namespace:

* BinaryFormatter
It's the most efficient way to serialize objetcs that will be available to use just by .NET Frameworkbased applications. If you are sure that your client opens the serialized objects by a .NET Framework application, BinaryFormatter would be the best.

* SoapFormatter
it's located in System.Runtime.Serialization.Formatters.Soap, and is reliable way to serialize objects that will bbe transmitted across a network or read by a non .NET Framework based application. SoapFormatter can work instead of BinaryFormatter too but the serialized object consume considerabaly more space. SOAP WEB services were the primarily target for SoapFormatter and even though that it can format data using Xml, but the most flexible way to perform serialization is using XML serialization for such a kind of situations.

SoapFormatter is not included as default like BinaryFormatter and you need to add System.Runtime.Serialization.Formatters.Soap.dll as reference.
Share/Bookmark

No comments: