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);
}
}
您是否设法解决了此问题?我被卡住了(是)。 –