title: How to produce an HTTP 403-equivalent WCF Message from an IErrorHandler?
body: <p>I want to write an <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.ierrorhandler.aspx" rel="nofollow noreferrer">IErrorHandler</a> implementation that will handle <code>AuthenticationException</code> instances (a proprietary type), and then in the implementation of <code>ProvideFault</code> provide a traditional Http Response with a status code of 403 as the fault message.  </p>
  
  <p>So far I have my first best guess wired into a service, but WCF appears to be ignoring the output message completely, even though the error handler is being called.</p>
  
  <p>At the moment, the code looks like this:</p>
  
  <pre><code>public class AuthWeb403ErrorHandler : IErrorHandler
  {
    #region IErrorHandler Members
    public bool HandleError(Exception error)
    {
      return error is AuthenticationException;
    }
  
    public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
    {
      //first attempt - just a stab in the dark, really
      HttpResponseMessageProperty property = new HttpResponseMessageProperty();
      property.SuppressEntityBody = true;
      property.StatusCode = System.Net.HttpStatusCode.Forbidden;
      property.StatusDescription = "Forbidden";
  
      var m = Message.CreateMessage(version, null);
  
      m.Properties[HttpResponseMessageProperty.Name] = property;
      fault = m;
    }
    #endregion
  }
  </code></pre>
  
  <p>With this in place, I just get the standard WCF html 'The server encountered an error processing the request. See server logs for more details.' - which is what would happen if there was no IErrorHandler.  Is this a feature of the behaviours added by WebServiceHost?  Or is it because the message I'm building is simply wrong!?  I can verify that the event log is indeed not receiving anything.</p>
  
  <p>My current test environment is a WebGet method (both XML and Json) hosted in a service that is created with the WebServiceHostFactory, and Asp.Net compatibility switched off.  The service method simply throws the exception in question.</p>