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)
Tags
WCF