NServiceBus/NServiceBus — pull request #1062 by danielmarbach (2013-03-18 22:40:47+00:00)
Title: Added capability to omit raw xml wrapping with property name

This commit adds a capability which I have discussed with @andreasohlund on skype chat. The idea is the following and helps to improve the interoperability story with XML messages. Currently we already have the possibility to omit the wrapping for better interoperability. Now there is another option on the XmlSerializer which allows to omit wrapping with the property name in case you are embedding XML raw data into the message.

Here is an example. With my support for XDocument and XElement over all serializer you can now define a message like:

public interface MyMessage
{
XElement SomeData { get; set; }
// more properties even other with XElement or XDocument
}

let's consider you want to send MyMessage with the following payload

...

If you serialize that with the xml serializer it turns into that:

...

with the new Option XmlSerializer(dontWrapRawXml : true) the serializer will serialize the message into the following format:

...

This is fine. BUT there is a convention which needs to be followed because somehow the serializer must be able to deserialize such payloads. Therefore the following convention is introduced:

== Important ==
When you use dontWrapRawXml the root node name of the XDocument or XElement MUST match (even casing) the name of the property declared on the message interface or class definition.

Without that convention it would not be possible to deserialize unwrapped XML data into the correct property.

The beauty of this is that you can fully leverage the power of all XML features including attributes on the payload without having to write a custom serializer for messages. This is especially useful for gateway message to external systems which need to define a strong schema.