We\'re connecting to a web service and the fault message we\'re getting back isn\'t deserializing (at all), and no version of class that I can make will deserialize correctly. W
What we ended up doing was to give up trying to catch the Fault and pass it back in the SOAP channel. Instead, we created a custom exception, and wired up a MessageInspector to watch for the faults and throw it as an exception.
The relevant part of the (sanitized) code:
public void AfterReceiveReply(ref Message reply, object correlationState)
{
if (reply.IsFault)
{
XmlDictionaryReader xdr = reply.GetReaderAtBodyContents();
XNode xn = XDocument.ReadFrom(xdr);
string s = xn.ToString();
XDocument xd = XDocument.Parse(s);
XNamespace nsSoap = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace ns = "http://eGov.gov";
XElement xErrorClass = xd.Element(nsSoap + "Fault").Element("detail").Element(ns + "eGov2Exception").Element(ns + "RequestErrorClassification");
XElement xErrorCode = xd.Element(nsSoap + "Fault").Element("detail").Element(ns + "eGov2Exception").Element(ns + "RequestErrorCode");
XElement xErrorMessage = xd.Element(nsSoap + "Fault").Element("detail").Element(ns + "eGov2Exception").Element(ns + "RequestErrorMessage");
throw new eGovException(xErrorClass.Value, xErrorCode.Value, xErrorMessage.Value);
}
}
The main application then uses:
catch (eGovException ex)
{
// Handles exception here.
}
Much too much time was wasted trying to correct name spaces. Thanks for answering.