title: IErrorHandler doesn't seem to be handling my errors in WCF .. any ideas?
body: <p>Have been reading around on IErrorHandler and want to go the config route.
  so, I have read the following in an attempt to implement it. </p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.ierrorhandler.aspx" rel="noreferrer">MSDN</a></p>
  
  <p><a href="http://nayyeri.net/configuration-error-for-custom-behavior-extensions-in-wcf" rel="noreferrer">Keyvan Nayyeri blog about the type defintion</a></p>
  
  <p><a href="http://www.neovolve.com/post/2008/04/07/implementing-ierrorhandler.aspx" rel="noreferrer">Rory Primrose Blog</a></p>
  
  <p>This is basically just the msdn example wrapped in a class that inherits IErrorHandler and IServiceBehaviour ... then this is wrapped in the Extension element that inherits from BehaviourExtensionElement to allegedly allow me to add the element into the web.config. What have i missed?</p>
  
  <p>I have got it to compile and from the various errors i have fixed it seems like WCF is actually loading the error handler. My problem is that the exception that i am throwing to handle in the error  handler doesn;t get the exception passed to it.</p>
  
  <p>My service implementation simply calls a method on another class that throws ArgumentOutOfRangeException - however this exception never gets handled by the handler.</p>
  
  <p>My web.config</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="basic"&gt;
            &lt;security mode="None" /&gt;                      
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;extensions&gt;
        &lt;behaviorExtensions&gt;
          &lt;add name="customHttpBehavior"
               type="ErrorHandlerTest.ErrorHandlerElement, ErrorHandlerTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt;
        &lt;/behaviorExtensions&gt;
      &lt;/extensions&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="exceptionHandlerBehaviour"&gt;          
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
            &lt;customHttpBehavior /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="exceptionHandlerBehaviour" name="ErrorHandlerTest.Service1"&gt;
          &lt;endpoint binding="basicHttpBinding" bindingConfiguration="basic" contract="ErrorHandlerTest.IService1" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
  </code></pre>
  
  <p>Service Contract</p>
  
  <pre><code>[ServiceContract]
  public interface IService1
  {
      [OperationContract]
      [FaultContract(typeof(GeneralInternalFault))]
      string GetData(int value);
  }
  </code></pre>
  
  <p>The ErrorHandler class</p>
  
  <pre><code>public class ErrorHandler : IErrorHandler , IServiceBehavior 
  {
      public bool HandleError(Exception error)
      {
          Console.WriteLine("caught exception {0}:",error.Message );
          return true;
      }
  
      public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
      {
         if (fault!=null )
         {
             if (error is ArgumentOutOfRangeException )
             {
                 var fe = new FaultException&lt;GeneralInternalFault&gt;(new GeneralInternalFault("general internal fault."));
                 MessageFault mf = fe.CreateMessageFault();
  
                 fault = Message.CreateMessage(version, mf, fe.Action);
  
             }
             else
             {
                 var fe = new FaultException&lt;GeneralInternalFault&gt;(new GeneralInternalFault(" the other general internal fault."));
                 MessageFault mf = fe.CreateMessageFault();
  
                 fault = Message.CreateMessage(version, mf, fe.Action);
             }
         }
      }
  
      public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection&lt;ServiceEndpoint&gt; endpoints, BindingParameterCollection bindingParameters)
      {
  
      }
  
      public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
      {
          IErrorHandler errorHandler = new ErrorHandler();
          foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
          {
              ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
              if (channelDispatcher != null)
              {
                  channelDispatcher.ErrorHandlers.Add(errorHandler);
              }
          }
      }
  
  
      public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
      {
  
  
      }
  }
  </code></pre>
  
  <p>And the Behaviour Extension Element</p>
  
  <pre><code>    public class ErrorHandlerElement : BehaviorExtensionElement 
      {
          protected override object CreateBehavior()
          {
              return new ErrorHandler();
          }
  
          public override Type BehaviorType
          {
              get { return typeof(ErrorHandler); }
          }
      }
  </code></pre>