title: How to add a Custom EndPointBehavior to the web.config of the service?
body: <p>I have followed <a href="http://www.codeproject.com/Articles/352678/Add-Custom-Message-Header-in-WCF-4-Calls" rel="noreferrer">this article</a> and have created <code>MyMessageInspector</code> and <code>MyEndPointBehavior</code> clases as below:</p>
  
  <pre><code>public class MyMessageInspector : IDispatchMessageInspector
  {
      public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
      { 
          Console.WriteLine("Incoming request: {0}", request);
          return null;
      }
  
      public void BeforeSendReply(ref Message reply, object correlationState)
      {
      }
  }
  
  public class MyEndPointBehavior : IEndpointBehavior
  {
      #region IEndpointBehavior Members
  
      public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
      {
      }
  
      public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
      {
      }
  
      public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
      {
          ChannelDispatcher channelDispatcher = endpointDispatcher.ChannelDispatcher;
          if (channelDispatcher != null)
          {
              foreach (EndpointDispatcher ed in channelDispatcher.Endpoints)
              {
                  ed.DispatchRuntime.MessageInspectors.Add(new MyMessageInspector());
              }
          }
      }
  
      public void Validate(ServiceEndpoint endpoint)
      {
      }
  
      #endregion
  }
  </code></pre>
  
  <p>How to add MyEndPointBehavior to the web.config?</p>
  
  <p>I've added the below extensions:</p>
  
  <pre><code>&lt;extensions&gt;
    &lt;behaviorExtensions&gt;
      &lt;add name="myMessageInspector" type="MessageInspectorProject.MyEndPointBehavior, MessageInspectorProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/&gt;
    &lt;/behaviorExtensions&gt;
  &lt;/extensions&gt;
  </code></pre>
  
  <p>But when I try to use it in below, it complains:</p>
  
  <pre><code>&lt;serviceBehaviors&gt;
      &lt;behavior&gt;
        &lt;myMessageInspector/&gt;
  </code></pre>
  
  <p>Its complain is as below:</p>
  
  <blockquote>
    <p>Invalid element in configuration. The extension 'myMessageInspector' does not derive from correct extension base type 'System.ServiceModel.Configuration.BehaviorExtensionElement'. </p>
  </blockquote>
  
  <p>How to add <code>MyEndPointBehavior</code> to the web.config?</p>