【发布时间】:2019-08-29 06:50:10
【问题描述】:
我尝试在我的 ASP.NET Core API 中引入来自 ASMX Websirvice 的 SOAP 异常。
旧版 ASMX Web 服务会抛出这样的 SOAP 异常:
<?xml version="1.0" encoding="utf-8"?>
<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:Client</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: An order must be specified
at legacyNamespace.Common.WebServiceBase.CheckUserPermissionsForProject(String projectId)
at legacyNamespace.CustomerApp.Defect.Defect.AcceptDefect(AcceptDefectModel defect)</faultstring>
<detail>
<errorCode>400</errorCode>
<message>An order must be specified</message>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
现在我正在尝试在我的 ASP.NET Core 2.2 Web API 中捕获和处理此异常:
try
{
// call the asmx service
}
catch (FaultException ex)
{
var fault = ex.CreateMessageFault();
if (fault.HasDetail)
{
var faultDetails = fault.GetDetail<XmlElement>();
var test = faultDetails.InnerText;
}
...
}
test var 仅包含错误代码“400”,仅此而已。 faultDetails ChildNode 为空。
如果我尝试调用GetDetail<XmlNode>(),则会出现序列化异常。
如何获取所有细节元素?
【问题讨论】:
标签: c# asp.net-core exception soap soapfault