-
Notifications
You must be signed in to change notification settings - Fork 18
Json Formatter Overview
mikeobrien edited this page Sep 14, 2010
·
2 revisions
The Json formatter simply uses the “out of the box” System.Runtime.Serialization.Json.DataContractJsonSerializer class.
The data contract json formatter can be configured declaratively on the service with the WcfRestContrib.ServiceModel.Description.WebDispatchFormatterConfigurationAttribute and WebDispatchFormatterMimeTypeAttribute:
[WebDispatchFormatterConfiguration("application/json")] [WebDispatchFormatterMimeType( typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.DataContractJson), "application/json")] 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/json"> <formatter mimeTypes="application/json" type="WcfRestContrib.ServiceModel.Dispatcher.Formatters.DataContractJson, 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 under Declarative Binding & Behavior Overview.