1
我有工作WCF REST Web服務,可以設置狀態碼和狀態說明像往常一樣:如何強制WebFaultException返回自定義錯誤?
OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse;
response.StatusCode = statusCode;
response.StatusDescription = detail.Error;
但我想用WebFaultException。不幸的是,alvays返回{「詳細信息」:「未找到」}當我運行我的代碼:
[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對象?