title: Custom Behavior won't register in my web.config
body: <p>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 <a href="https://web.archive.org/web/20190126174548/https://blogs.msdn.microsoft.com/carlosfigueira/2011/05/02/wcf-extensibility-message-formatters/" rel="nofollow noreferrer">this blog</a> for how I've attached it.</p>
  <p>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 <a href="http://msdn.microsoft.com/en-us/library/aa734726.aspx" rel="nofollow noreferrer">msdn article</a>.</p>
  <p>So I try to do that like so:</p>
  <pre><code>&lt;behaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name=&quot;jsonRest&quot;&gt;
        &lt;webHttp defaultOutgoingResponseFormat=&quot;Json&quot; /&gt;
        &lt;NewtonsoftJsonBehavior/&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name=&quot;&quot;&gt;
        &lt;serviceMetadata httpGetEnabled=&quot;true&quot; /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults=&quot;false&quot; /&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;extensions&gt;
    &lt;behaviorExtensions&gt;
      &lt;add name=&quot;NewtonsoftJsonBehavior&quot; type=&quot;Newtonsoft.Json.Extensions.NewtonsoftJsonBehavior, NewtonsoftJsonExtensions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null&quot; /&gt;
    &lt;/behaviorExtensions&gt;
  &lt;/extensions&gt;
  </code></pre>
  <p>Sadly, I'm unable to make that work. When I do that, Visual Studio tells me that</p>
  <blockquote>
  <p>The element 'behavior' has invalid child element 'NewtonsoftJsonBehavior'</p>
  </blockquote>
  <p>In the afforementioned <a href="http://msdn.microsoft.com/en-us/library/aa734726.aspx" rel="nofollow noreferrer">msdn article</a>, it's said that</p>
  <blockquote>
  <p>To add configuration abilities to the element, you need to write and register a configuration element. For more information on this, see the <a href="http://msdn.microsoft.com/en-us/library/system.configuration.aspx" rel="nofollow noreferrer">System.Configuration</a> documentation.</p>
  <p>After the element and its configuration type are defined, the extension can be used, as shown in the following example.</p>
  </blockquote>
  <p>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 <a href="http://msdn.microsoft.com/en-us/library/system.configuration.aspx" rel="nofollow noreferrer">System.Configuration</a> which is supposed to tell me how to do this. So that's basically my question:</p>
  <p><strong>How do I write and register the configuration element, and if that's not my problem, what is the problem?</strong></p>
  <p>Many thanks in advance!</p>