Skip to content

Xml Formatter Overview

mikeobrien edited this page Sep 14, 2010 · 2 revisions

The xml formatter simply uses the “out of the box” System.Runtime.Serialization.DataContractSerializer class.

This formatter will serialize data contract namespaces and require them in the xml upon deserialization. It will also serialize xml schema attributes and enforce element order. To avoid these, use the POX formatter described under POX Formatter Overview.

The data contract formatter can be configured declaratively on the service with the WcfRestContrib.ServiceModel.Description.WebDispatchFormatterMimeTypeAttribute:

[WebDispatchFormatterConfiguration("application/xml")]
[WebDispatchFormatterMimeType(
    typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.DataContract),
    "application/xml", 
    "text/xml")]
public class Books : IBooksService {...}

Or in configuration:

<system.serviceModel>
    <extensions>
        <behaviorExtensions>
            <add name="webFormatter" 
                 type="WcfRestContrib.ServiceModel.Configuration.WebDispatchFormatter.ConfigurationBehaviorElement, WcfRestContrib, 
                       Version=x.x.x.x, Culture=neutral, PublicKeyToken=89183999a8dc93b5"/>
        </behaviorExtensions>
    </extensions>
    <serviceBehaviors>
        <behavior name="Rest">
          <webFormatter>
            <formatters defaultMimeType="application/xml">
              <formatter mimeTypes="application/xml,text/xml" 
                         type="WcfRestContrib.ServiceModel.Dispatcher.Formatters.DataContract, WcfRestContrib"/>
            </formatters>
          </webFormatter>
        </behavior>
    </serviceBehaviors>
</system.serviceModel>

One or more formatters can be defined.

NOTE: The WcfRestContrib.ServiceModel.Web.WebServiceHost allows you to specify configuration based behaviors if you do not want to specify this declaratively. See more about it under Declarative Binding & Behavior Overview.

Clone this wiki locally