I am successfully working with a third party soap service. I have added a service reference to a soap web service which has auto generated the classes.
When an error oc
Here's a few methods I've found of extracting that detailed exception information from FaultExceptions
catch (FaultException e)
{
var errorElement = XElement.Parse(e.CreateMessageFault().GetReaderAtDetailContents().ReadOuterXml());
var errorDictionary = errorElement.Elements().ToDictionary(key => key.Name.LocalName, val => val.Value);
var errorMessage = errorDictionary?["ErrorMessage"];
}
Example Output:
Organization does not exist.
catch (FaultException e)
{
var errorElement = XElement.Parse(e.CreateMessageFault().GetReaderAtDetailContents().ReadOuterXml());
var errorDictionary = errorElement.Elements().ToDictionary(key => key.Name.LocalName, val => val.Value);
var errorDetails = string.Join(";", errorDictionary);
}
Example Output:
[ErrorMessage, Organization does not exist.];[EventCode, 3459046134826139648];[Parameters, ]
var errorElement = XElement.Parse(e.CreateMessageFault().GetReaderAtDetailContents().ReadOuterXml());
var xmlDetail = (string)errorElement;
Example Output:
Organization does not exist. 3459046134826139648