从ASMX Web Services C#返回用户友好或干净的SOAP异常



我很难更改ASMX Web Services C#中异常返回的SOAP消息。下面是现在返回的Soap消息异常:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ApplicationException: Module Authorization Failed
at BackEnd.Services.Models.ModuleCredential.IsValid(String serviceName)
at BackEnd.DashboardPSI.HelloWorld()
--- End of inner exception stack trace ---</faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>

我想改成这样:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. ---> Module Authorization Failed</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>

我在NetFramework 4.5上使用ASMX WebServices。并使用SoapExtension记录异常。感谢

public class Base: System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
throw new ApplicationException("Module Authorization Failed");
}
}

已更新因此,当在开发环境中时会发生带有内部异常的错误返回,当我放入生产环境中时,内部异常会被隐藏。感谢

因此,当在开发环境中时,会发生带有内部异常的错误返回,当我放入生产环境时,内部异常会被隐藏。感谢

相关内容

  • 没有找到相关文章

最新更新