This site has been taken over by the staff of www.ASPDeveloper.Net

Please report errors to suggest@aspdeveloper.net

BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
WCF, WS, SOAP
A Serialized SOAP Message
Retrieving Message Headers
SOAP Headers
Deserializing an Object Graph
Serializing an Object Graph
The SoapFormatter
Runtime Object Serialization
Importance of a UDDI based Service Registry
BizTalk and WCF: Part V, Publishing Operations Patterns
BizTalk and WCF: Part IV, Attachment Patterns
BizTalk and WCF: Part III, Transaction Patterns
BizTalk and WCF: Part II, Security Patterns
BizTalk and WCF: Part I, Operation Patterns
Accessing UDDI using Apache Scout APIs
Storing state in an XML property bag
UDDIExplorer
XslTransport for PocketSOAP
Kafka - XSLT SOAP Toolkit
VB Web services Proxy Generator
Using msxml3 with Web Storage System
<< Uncategorized
XALAN >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :3796

 

SoapFormatter vs XmlSerializer

The .NET Framework offers two entirely different solutions to serialize objects. The .NET Framework employs both to create and process SOAP messages in different scenarios. The first one builds on top of the XmlSerializer discussed in detail in chapters 9 and 10 and is used by the framework internally to create SOAP messages within ASP.NET WebServices. The second solution is built around the SoapFormatter in the serialization framework and is used by the remoting infrastructure, which is the main carrier for Inter Process Communication (IPC) inside the .NET platform.

Interoperability

The design goals of the SoapFormatter are very different from the ones of the XmlSerializer. The latter’s focusses on mapping .NET classes to XML types defined by an XSD schema. It provides lots of flexibiliy to customize the mappings between the two to be able to map classes to virtually every schema type. This makes the XmlSerializer a powerful tool if our application needs to interoperate with other systems through the exchange of XML documents, but it is not intended as a general purpose serialization solution. Likewise, we can develop classes the XmlSerializer can map to an XML document even if the document was not created the XmlSerializer because it does not rely on type information inside the SOAP message to map schema types to programmatic types. Instead we have to provide the XmlSerializer with information about the type mappings before it can do its work. Usually, we provide the information in the form of metadata attributes attached to classes specially designed to map to XSD schema types.

Runtime serialization on the other hand focuses on an accurate description of the serialized object, not the format of the description. Customization of the format is not an issue because the SoapFormatter assumes that it performs both, serialization and deserialization of an object. Other than the XmlSerializer, the SoapFormatter embeds all type information required to deserialize objects directly into the message. This approach limits interoperability considerably because it requires applications that exchange messages have access to the same assemblies.

Performance

Another aspect where the two solutions differ considerably is performance. Microsoft designed the XmlSerializer for high performance and moved all the expensive computing operations into the constructor. The constructor analyzes all types it can process up front and internally creates compiled classes that can serialize and deserialize these types very fast. As a consequence, Serialize() and Deserialize() are very fast operation because the serializer leverages these classes instead of analyzing the structure of each object over and over again.

The SoapFormatter behaves the opposite way; the constructor does not require any information about types it will process up front. In return it has to analyze the structure of each object it processes. Compared side-by-side serializing identical objects, the XmlSerializer is up to 6x faster than SoapFormatter for simple classes and this performance gap grows wider with the complexity of the serialized classes. This makes the XmlSerializer the solution of choice for high throughput applications, like ASP.NET WebServices and the XmlMessageFormatter for message queues.

Summary

This chapter introduced us to object serialization with the SoapFormatter. We have seen how we can persist complete object graphs to SOAP messages and re-hydrate the graphs from the message at a later point. We built a custom messaging framework around the SoapFormatter to interact with other applications over the SOAP protocol. The strong type safety of the SoapFormatter’s serialization format hampers its ability to interoperate with other platforms, but it provides a type safe solution to communicate between distributed components running on the .NET platform.

Alternatively, many people persist objects with the SoapFormatter for storage purposes only because the formatter can serialize the complete internal state of a large number of classes. Persisting objects with the SoapFormatter also takes advantage of the strong type safety and provides the benefits of an XML-based storage format, which makes it easy to verify to serialized data and works well with text search enabled databases, like SQL Server.


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Software Specialist, Linux - Finlan
Linux Core Technical Project Manage
Graphics designer at Tanzania. Expe
Integration Specialist Needed - Wor
Virtualization Server Infrastructur

View all Jobs (Add yours)
View all CV (Add yours)






    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP