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
One way to handle this if serialization is failing completely is to use a OoperationContract using the Message type as input and output. This way you can manually parse the XML when Iffault == true or use GetBody() to get the regular contents if no error occurred.
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.
First of all, if you cannot get the WSDL from the people who produced this web service, then they have no business having a SOAP-based web service. A proper WSDL would solve your problem, whether or not "?WSDL" is used.
Second, please post the code of the eGov2ExceptionType
class. I suspect it does not have the http://eGov.gov
namespace set on it.