Kirk Evans Blog

.NET From a Markup Perspective

Control Serialization and XSD.exe Using .NET 2.0

Keith is asking for a version of XSD.exe that lets him control serialization, specifically controlling properties versus fields in the generated proxy and control of collection serialization. 

Might as well give us an extensible xsd.exe compiler that actually allows us to control the xsd->class mappings (properties versus fields, COLLECTIONS versus arrays, etc). I say this because I doubt the asmx team is going to do this for us.

Keith, you’re going to love .NET 2.0.

First, XSD.exe includes a new /fields switch to indicate if you want the generated proxy to use public fields or properties, the default behavior is to generate proxies with properties instead of fields.

Second, you have tight control over the serialization of types using xsd.exe under .NET Framework 2.0.  Go to Yasser’s site and see the deck and code for the “Web services, serialization and networking in .NET Framework 2.0” presentation he did at TechEd.  In the SongStream.cs class in the NetTunes project, you will see how he used a new attribute introduced in .NET 2.0, XmlSchemaProvider, that indicates the static method that will be called to generate the schema.   Yasser’s project also includes a project, NetTunesSIE, which is an implementation of a SchemaImporterExtension, that is used to control the proxy generation.  Yasser’s example simply adds the namespace “NetTunes” to the CodeDom, ensuring that the generated proxy is in a namespace. 

In .NET 2.0, you have access to the CodeDom to control the proxy generation behavior as well as the ability to control the schema representation.