2
當我的代碼中有異常時,我想根據它是REST還是SOAP,將它作爲FaultException/WebFaultException返回。以下問題與我的項目的REST組件有關。異常被觸發,我在我的調試窗口中看到它(見圖片)。WCF Rest WebFaultException總是返回202
我們清楚地看到,WebFaultException被觸發,但我的JSON響應不是HTTP錯誤請求也不是我的異常消息有,但始終執行以下操作:
{"readyState":4,"responseText":"","status":202,"statusText":"Accepted"}
這裏我的界面:
[WebInvoke(Method = "POST", UriTemplate = "/Package/", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
[FaultContract(typeof(FaultException))]
[OperationContract]
string CopyZip(Stream zippedPackage);
下面是它的實現:
public string CopyZip(Stream zippedPackage)
{
try
{
ZipCreator pck = new ZipCreator();
pck.CopyUploadedZip(zippedPackage);
return "Zipped";
}
catch (Exception ex)
{
//throw new FaultException(ex.Message);
throw new WebFaultException<string>(ex.Message, HttpStatusCode.BadRequest);
}
}
您是否設法解決了此問題?我被卡住了(是)。 –