Skip to content

Latest commit

 

History

History
47 lines (26 loc) · 1.68 KB

File metadata and controls

47 lines (26 loc) · 1.68 KB
title summary redirects related
Xml Serializer
A custom written XML serializer.
nservicebus/serialization/xml-serializer
samples/serializers/xml

A custom written XML serializer.

Usage

snippet: XmlSerialization

Raw XML

In certain integration scenarios you might want to bypass NServiceBus opinionated serialization format (essentially key/value pairs) and directly send custom XML structures over messaging. In order to do that you can simply declare one or multiple properties on the message contract as XDocument or XElement.

snippet: MessageWithXDocument

snippet: MessageWithXElement

The caveat of this approach is that the serializer will wrap the data in an outer node being named after the name of the property. So in the examples above you can see the associated expected payloads.

If you would like to avoid that for interoperability reasons you need to instruct the serializer to not wrap raw xml structures like the following

snippet: ConfigureRawXmlSerialization

INFO: The name of the property on the message must exactly match the name of the root node in the xml structure in order to be able to correctly deserialize the no longer wrapped content.

Caveats

XML Attributes

The XML serializer in NServiceBus is a custom implementation. As such it does not support the standard .NET XML Attributes.

Unsupported Types

  • HashTable
  • Types with non-default constructors. So types must have a public constructor with no parameters.
  • ArrayList