title: how to overcome System.ServiceModel.FaultException
body: <p>While updating a service reference of my WCF client (simply by clicking Update Service Reference in Visual Studio 2008), following error occurs: <strong>System.ServiceModel.FaultException</strong>: The message ...</p>
  
  <p>I've created ErrorServiceBehaviour class. Because such a behavior is created for error handling, IErrorHandler implementation must be applied to each ChannelDispatcher.</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 ErrorServiceBehavior attribute to my service class:</p>
  
  <p><strong>[ErrorServiceBehavior(FaultType = typeof(MyServiceFault))]</strong> </p>
  
  <pre><code>public class MyService : IMyService
  {
     ...
  }
  </code></pre>
  
  <p>The thing is, when I comment out the foreach loop inside ApplyDispatchBehavior method, I get no 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>