blog community

Welcome to blog community Sign in | Join | Help
in Search

Wouter van Vugt

This blog is no longer maintained and has moved

Having fun with the XmlSchemaProvider: Serializing object trees

About a year ago I became very enthusiastic. I found a new attribute in the framework which allows you to determine the WSDL contract which describes my objects. Used in conjunction with the IXmlSerializable interface you can also make sure the serializer pumps out the correct XML, corresponding to the custom Xml-Schema inside the WSDL. Why is this so important? The default XmlSerializer requires all fields to have public get / set properties. This means my Product object needs a public get/set ID property. I personally didn’t want a settable ID property, because it is the never-changing primary key for that object. Furthermore I don’t want to change the public interface of my objects just because they’ll be serialized into a Soap message. Using XmlSchemaProvider with IXmlSerializable you can fix all this; keep only the getter, and still serialize the ID.

Now all of this sounds good of course, and there are various samples on the internet showing how you can use these two classes to serialize your own ‘Product’ objects. However, the examples I found only show how to serialize a single object, not a tree of objects, such as an Order-OrderItem combination or Order-Customer-Address. Is this more difficult then? Well, yeah, a tad-bit, because you’ll have to share the Xml-Schema definition somehow

 

Read more...  or Download the code...

Published Tuesday, May 09, 2006 9:19 AM by wouterv
Filed under: , ,

Comments

No Comments
Anonymous comments are disabled

This Blog

Syndication

News


Add to Technorati Favorites
Powered by Community Server, by Telligent Systems