title: ContractFilter mismatch at the EndpointDispatcher (error handling)
body: <p>While updating a service reference of my WCF client (simply by clicking <em>Update Service Reference</em> in Visual Studio 2008), following error occurs:</p>
  
  <blockquote>
    <p>System.ServiceModel.FaultException:
    The message with Action
    '<a href="http://schemas.xmlsoap.org/ws/2004/09/transfer/Get" rel="noreferrer">http://schemas.xmlsoap.org/ws/2004/09/transfer/Get</a>'
    cannot be processed at the receiver,
    due to a ContractFilter mismatch at
    the EndpointDispatcher. This may be
    because of either a contract mismatch
    (mismatched Actions between sender and
    receiver) or a binding/security
    mismatch between the sender and the
    receiver.  Check that sender and
    receiver have the same contract and
    the same binding (including security
    requirements, e.g. Message, Transport,
    None).     at
    System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(Exception
    e, Message message)</p>
  </blockquote>
  
  <p>Background: </p>
  
  <p>I've created <code>ErrorServiceBehaviour</code> class. Because such a behavior is created for error handling, <code>IErrorHandler</code> implementation must be applied to each <code>ChannelDispatcher</code>. </p>
  
  <pre><code>public class ErrorServiceBehaviour : Attribute, IServiceBehavior
  {
     ...
     public Type FaultType
     {
        get { return _faultType; }
        set { _faultType = value; }
     }
  
     public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
     {
         foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
         {
             dispatcher.ErrorHandlers.Add(new ErrorHandler(_faultType));
         }
     }
  }
  
  public class ErrorHandler : IErrorHandler
  {
       public ErrorHandler(Type faultType)
       {
          _faultType = faultType;         
       }
       ...
  }
  </code></pre>
  
  <p>Later, I've used that behaviour by applying <code>ErrorServiceBehavior</code> attribute to my service class:</p>
  
  <pre><code>[ErrorServiceBehavior(FaultType = typeof(MyServiceFault))] 
  public class MyService : IMyService
  {
     ...
  }
  </code></pre>
  
  <p>The thing is, when I comment out the <code>foreach</code> loop inside <code>ApplyDispatchBehavior</code> method, I get <strong>no</strong> error at all, but that is not the way out (because I want my errors to be handled).</p>
  
  <p>Below there is my service config:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;services&gt;
          &lt;service behaviorConfiguration="DefaultBehavior" name="MyService"&gt;
              &lt;endpoint address="" binding="wsHttpBinding" contract="IMyService" bindingConfiguration="NoSecurityBinding"/&gt;
              &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
          &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
          &lt;serviceBehaviors&gt;
              &lt;behavior name="DefaultBehavior"&gt;
                  &lt;serviceMetadata httpGetEnabled="true" /&gt;
                  &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
              &lt;/behavior&gt;
          &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;bindings&gt;
          &lt;wsHttpBinding&gt;
              &lt;binding name="NoSecurityBinding" &gt;
                  &lt;security mode="None"&gt;
                      &lt;transport clientCredentialType="None"/&gt;
                      &lt;message establishSecurityContext="false"/&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
              &lt;binding name="DefaultBinding" /&gt;
          &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Can someone help me?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The code shown earlier:</p>
  
  <pre><code>foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
  {
      dispatcher.ErrorHandlers.Add(new ErrorHandler(_faultType));
  }
  </code></pre>
  
  <p>adds custom error handling for all endpoints - including the metadata one. But actually this is <strong>not</strong> the source of the problem - even when I disable adding error handling for metadata endpoint, the issue still occurs.</p>
  
  <p>The other notice is, when I change the <code>bindingConfiguration</code> of the first endpoint to <code>DefaultBinding</code>, I have <strong>no</strong> error at all:</p>
  
  <pre><code>&lt;services&gt;
      &lt;service behaviorConfiguration="DefaultBehavior" name="MyService"&gt;
          &lt;endpoint address="" binding="wsHttpBinding" contract="IMyService" bindingConfiguration="DefaultBinding"/&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
      &lt;/service&gt;
  &lt;/services&gt;
  </code></pre>
  
  <p>Such an option in also not what I want - I still need problematic <code>NoSecurityBinding</code> to work. </p>
  
  <p>Thanks in advance.</p>