2005-08-16
| Table of Contents: |
| Rate This Article: | Add This Article To: |
( Page 2 of 3 )
XML Serialization
XML serialization works by converting an object to XML data. This is sometimes referred to as SOAP serialization, because it uses the Simple Object Access Protocol, a precisely defined and widely supported XML dialect for representing objects as XML data.
XML serialization has certain advantages, because the resulting data stream is nothing more than XML, which is plain text, and it can be transferred essentially without restriction over networks that have security measures in place to block other kinds of data.
It is for this very reason that SOAP is used for Web services.
Suppose you have a simple class, such as this:
Public Class Person
Public FirstName As String
Public LastName As String
End Class
The XML serialization of an object based on this class would result in data something like this:
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <a1:Person id= "ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Serialize/Serialize %2C%20Version%3D1.0.2043.15967%2C%20 Culture%3Dneutral%2C%20PublicKeyToken%3Dnull"> <FirstName id="ref-3">Hiram</FirstName> <LastName id="ref-4">Schmedlap</LastName> </a1:Person> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
XML serialization has some limitations. It converts public property values and fields, but does not encode type information. Also it does not encode private properties and fields, which requires binary serialization. Any class to be serialized to XML must have a public, parameterless constructor. One advantage of XML serialization is that the serialized data, being XML, rarely has any problems passing over networks and through security measures, such as firewalls, that might be unhappy with a binary data stream. For this reason, XML serialization is used by .Net Web services. Another advantage is that XML serialization is not platform-specific. In other words, you do not have to have .Net or Windows on both ends of the process.
![]() |
|


