|
Yesterday a customer got in touch with me regarding some custom serialization/deserialization issues in his ASMX-based Web Services. When using IXmlSerializable there are essentially three 'rules' to follow: - In WriteXml
- Don't ever write the root element, but have it specified as XmlRoot. The XmlSerializer instance will create the root element (or SOAP body will replace the root with whatever name it bears)
-
- In ReadXml
- Pretend the root is always there
-
- On schema imports
- Avoid the duplicate global element problem: check to make sure that the schema isn't already in the SchemaSet
if(!schemaSet.Contains(mySchema.Id)) { schemaSet.Imports.Add(mySchema); }
-
Nothing spectacular, just to keep in mind. Here is a great post by Kirk to look at if you want to deal with IXmlSerializable. BTW: IXmlSerializable stays important in WCF land: go and read the invaluable serialization rules by Sowmy. So, it rulez :)
|