I have a working application using Json.NET (newtonsoft) as a custom serializer. Currently I'm adding this derivative of WebHttpBehavior in a custom WebServiceHostFactory. See the code snippet at the end of this blog for how I've attached it.
As I'm hosting this service in IIS, I would like to get rid of my custom hosting code and simply add the custom behavior to my web.config. The procedure is shown in this msdn article.
So I try to do that like so:
<behaviors>
<endpointBehaviors>
<behavior name="jsonRest">
<webHttp defaultOutgoingResponseFormat="Json" />
<NewtonsoftJsonBehavior/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="NewtonsoftJsonBehavior" type="Newtonsoft.Json.Extensions.NewtonsoftJsonBehavior, NewtonsoftJsonExtensions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
Sadly, I'm unable to make that work. When I do that, Visual Studio tells me that
The element 'behavior' has invalid child element 'NewtonsoftJsonBehavior'
In the afforementioned msdn article, it's said that
To add configuration abilities to the element, you need to write and register a configuration element. For more information on this, see the System.Configuration documentation.
After the element and its configuration type are defined, the extension can be used, as shown in the following example.
I've got this feeling that what I'm missing is exactly that. Somehow registering the element and its configuration type. Sadly I can't make heads or tails of the System.Configuration which is supposed to tell me how to do this. So that's basically my question:
How do I write and register the configuration element, and if that's not my problem, what is the problem?
Many thanks in advance!