我有工作的 WCF REST Web 服务,可以像往常一样设置状态代码和状态描述:
OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse;
response.StatusCode = statusCode;
response.StatusDescription = detail.Error;
但我想使用 WebFaultException。不幸的是,当我运行我的代码时,它总是返回 {"Detail":"Not Found"}:
[Serializable]
[DataContract]
public class DtoError
{
public DtoError()
{
}
public DtoError(string error)
{
Error = error;
}
[DataMember]
public string Error { get; private set; }
}
var error = new DtoError(entityName + " is not existing");
throw new WebFaultException<DtoError>(error, HttpStatusCode.NotFound);
我可以返回我的自定义错误 json 对象吗?