views:

21

answers:

0

I've developed a service using webHttpBinding and i'm having problems with getting the StatusDescription on the client. I'm able to set the StatusCode. I've tried some code i've found through google with no success. This is the errorhandler i'm using:

public class ErrorHandlerEx : IErrorHandler {

    public bool HandleError(Exception error)
    {
        return true;
    }



    void IErrorHandler.ProvideFault(Exception error, MessageVersion version, ref Message fault)
    {
        fault = Message.CreateMessage(MessageVersion.None, "", new ErrorBodyWriter() { Code = "9999", Message = error.Message });
        HttpResponseMessageProperty prop = new HttpResponseMessageProperty();
        prop.Headers[System.Net.HttpResponseHeader.ContentType] = "text/html";
        prop.StatusCode = System.Net.HttpStatusCode.InternalServerError;
        prop.StatusDescription = error.Message;
        fault.Properties[HttpResponseMessageProperty.Name] = prop;
        WebBodyFormatMessageProperty formatProp = new WebBodyFormatMessageProperty(WebContentFormat.Xml);
        fault.Properties[WebBodyFormatMessageProperty.Name] = formatProp;
        WebOperationContext.Current.OutgoingResponse.SuppressEntityBody = false;
        WebOperationContext.Current.OutgoingResponse.StatusCode = prop.StatusCode;
    }
}