Serializing XML to XML

How should I represent raw XML content in a contract?

It seems like it would be really easy to have within the large blob of XML that makes up a message, a small blob of XML. However, it’s more challenging to deal with that situation than you might expect because that small blob of XML has to be handled unlike everything else. With most contracts you can chew along the message and place each of the resulting bits in its proper place. When trying to preserve the raw XML though, you have to know when not to chew.

In your contract you should use XMLSerializer formatted fields to turn off most of the unnecessary thinking regarding the XML content. Then, XmlSerializer knows about special handling for XmlElement and XmlAttribute to complete the mapping between pieces in the message and fields in your type. These two types work under the covers with XmlSerializer even though they don’t implement the standard contract for serialization.

With Orcas, you can also use the new XElement type that is defined by XLinq. XLinq doesn’t have any deep integration with XmlSerializer but XElement directly implements the IXmlSerializable contract to make things work.

Next time: Mapping Client Certificates

Comments (2)

  1. How do I run a custom event once when the service is first started? The easiest way to execute some custom

  2. Alexey Lavnikov says:

    An example of working [DataContract] attributed class with mixed [DataMember] members and xml content would be really appreciated.