Returning Http Status Code with WCF webHttpBinding

WCF

 In order to return a standard HTTP response with a status code and optionally some data, we need to throw the WebFaultException

class ErrorData {
    int Code;
    string Message;
}

...

var errorData = new ErrorData() {
    Code = 222,
    Message = "Some details..."
}
throw new WebFaultException<ErrorData>(errorData, HttpStatusCode.BadRequest)

Post a Comment

Previous Post Next Post