Implementing Custom Serialization
XML serialization supports the ability to serialize instances of an ADO.NET DataSet as well as classes that derive from the DataSet class. It can do this because the DataSet class implements the IXmlSerializable interface.
A .NET type that needs more advanced control over the way it is serialized can implement the IXmlSerializable interface. As of this writing, the ADO.NET DataSet is the only .NET type that implements this interface. Unfortunately, this interface is intended to be used only internally within the .NET Framework. Hopefully, this interface will be available to developers in the future.
The signature of the IXmlSerializable interface is as follows:
public interface IXmlSerializable { System.Xml.Schema.XmlSchema GetSchema(); void ReadXml(System.Xml.XmlReader reader); void WriteXml(System.Xml.XmlWriter writer); }
The GetSchema method is called when the ASP.NET runtime generates the WSDL document for the Web service. The ReadXml method is called when the SOAP message received from the client is being deserialized. The WriteXml method is called when the response SOAP message is being serialized.
When a strongly typed ADO.NET record set is exposed by the interface of a Web service, the schema for the strongly typed record set is resolvable using an external URL. For example, say I have a strongly typed record set called MyRecordSet that is exposed by a Web service addressable at http://somedomain/MyWebService.asmx. The schema for MyRecordSet would therefore be located at http://somedomain/MyWebService.asmx?MyRecordSet.
The URL that references the MyRecordSet schema is imported into the schema for the Web service itself. Calls to this URL will return the schema produced by calling the WriteXmlSchema method exposed by the MyRecordSet class.