I try to cath a SOAP exception from ASMX Websirvice in my ASP.NET Core API.
The legacy ASMX Webservice throw a SOAP Exception like this:
<?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>
Now I'm trying to catch and process this exception in my 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;
}
...
}
And the test
var contains only the errorCode "400" and nothing more. faultDetails
ChildNodes are empty.
If I try to call GetDetail<XmlNode>()
than I got a serialization exception.
How can I get all detail elements?