Summary

Chapter 7

XML Serialization

The ASP.NET runtime is built on top of a technology called XML serialization. XML serialization is responsible for serializing instances of .NET types to XML and deserializing XML to instances of .NET types. XML serialization is also responsible for serializing .NET type definitions to XML schemas and deserializing XML schemas to .NET type definitions.

Sometimes, this default behavior might not entirely meet your needs. For example, public properties and fields will be serialized into elements within the resulting XML document, but many existing and emerging Web services interfaces such as UDDI and .NET My Services expose interfaces that use attributes. Therefore, you need a means of controlling how .NET types and instances of .NET types are serialized into XML.

Consider the following SOAP message, which submits a purchase order:

<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema">   <soap:Body>     <PurchaseOrder xsi:type="CommentedPurchaseOrder"      xmlns="http://tempuri.org/">       <BillingAddress>         <Name accountNumber="12345">ABC Company</Name>         <Street>123 Some Street</Street>         <City>Some Town</City>         <State>CO</State>         <ZipCode>80427</ZipCode>       </BillingAddress>       <ShippingAddress>         <Name accountNumber="12345">ABC Company</Name>         <Street>123 Some Street</Street>         <City>Some Town</City>         <State>CO</State>         <ZipCode>80427</ZipCode>       </ShippingAddress>       <Items>         <Item partNumber="A1467">           <Quantity>2</Quantity>           <Price>23.5</Price>           <Currency>US_DOLLAR</Currency>         </Item>         <Item partNumber="C2963">           <Quantity>20</Quantity>           <Price>10.95</Price>           <Currency>US_DOLLAR</Currency>         </Item>         <Item partNumber="F4980">           <Quantity>3</Quantity>           <Price>82.65</Price>           <Currency>US_DOLLAR</Currency>         </Item>       </Items>       <Comments>Please do not ship a partial order.</Comments>     </PurchaseOrder>   </soap:Body> </soap:Envelope>

The message contains a mixture of elements and attributes. For example, the part number for each item listed in the purchase order is serialized within the partNumber attribute of each Item element. The Name element within the billing and shipping addresses contains the name of the company as well as an attribute that contains the company's account number.



Building XML Web Services for the Microsoft  .NET Platform
Building XML Web Services for the Microsoft .NET Platform
ISBN: 0735614067
EAN: 2147483647
Year: 2002
Pages: 94
Authors: Scott Short

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