Hello,
I'm trying to build a C# client to consume an AXIS Web Service (running SOAP
over HTTP). The Web Service encodes full server-side exception traces in the
Soap Fault > Detail element using
complex type structures declared in the WSDL file.
I have had absolutely no luck working out how I can deserialize the custom
server exception object out of the detail element.
I have tried XmlSerializer as suggested in the mailing list with absolutely
no luck.
try
{
<<<< e.g. some operation >>>>
}
catch (System.Web.Services.Protocols.SoapException e)
{
try
{
System.Xml.Serialization.XmlSerializer ser=
new System.Xml.Serialization.XmlSerializer(typeof
(FdkException));
System.IO.StringReader sr= new
System.IO.StringReader(e.Detail.InnerXml);
FdkException fault= (FdkException) ser.Deserialize(new
System.Xml.XmlTextReader(sr));
FdkException fault= (FdkException) ser.Deserialize(new
System.Xml.XmlTextReader(stream));
}
catch (Exception ex)
{
System.Console.WriteLine(ex.toString());
throw;
}
}
I set SoapType options in the FdkException class(generated through wsdl) as
mentioned in the mailing list
....
[Serializable]
[System.Xml.Serialization.XmlType("Fault",
Namespace="http://xmlns.mycompany.com/content/ws")]
[System.Xml.Serialization.XmlRoot("Fault",
Namespace="http://xmlns.mycompany.com/content/ws")]
[System.Xml.Serialization.SoapTypeAttribute("FdkExc eption",
"http://xmlns.mycompany.com/content/ws")]
public class FdkException
{
public string errorCode;
public FdkExceptionEntry[] exceptionEntries;
public string serverStackTraceId;
}
[Serializable]
[SoapTypeAttribute(“FdkExceptionEntry”,"http://xmlns.mycompany.com/app/ws")]
public class FdkExceptionEntry
{
public string errorCode;
public long id;
public string serverStackTraceId;
}
This deserialization approach resulted in an exception:
Exception Type: System.InvalidOperationException
Message: <fault xmlns='http://xmlns.mycompany.com/content/ws'> was not
expected.
Below is the SOAP message returned from the server on an invalid operation
attempt (including Fault):-
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body>
<soapenv:Fault><faultcode>soapenv:Server.userExcep tion</faultcode><faultstring>MYCOMPANY.FDK.AggregateErro r: MYCOMPANY.FDK.AggregateError</faultstring>
<detail> =====>> This is what we are tying to deserialise to
FdkException
<ns1:fault xsi:type="ns1:FdkException"
xmlns:ns1="http://xmlns.mycompany.com/content/ws"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<exceptionEntries soapenc:arrayType="ns1:FdkExceptionEntry[1]"
xsi:type="soapenc:Array"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<exceptionEntries xsi:type="ns1:FdkExceptionEntry">
<detailedErrorCode
xsi:type="xsd:string">MYCOMPANY.FDK.ServerError</detailedErrorCode>
<errorCode
xsi:type="xsd:string">MYCOMPANY.FDK.UnexpectedErro r</errorCode>
<id xsi:type="xsd:long">0</id>
<serverStackTraceId
xsi:type="xsd:string">22-1132729995032</serverStackTraceId>
</exceptionEntries>
</exceptionEntries>
<detailedErrorCode
xsi:type="xsd:string">MYCOMPANY.FDK.AggregateError </detailedErrorCode>
<errorCode
xsi:type="xsd:string">MYCOMPANY.FDK.AggregateError </errorCode>
<serverStackTraceId xsi:type="xsd:string"></serverStackTraceId>
</ns1:fault>
</detail>
</soapenv:Fault></soapenv:Body></soapenv:Envelope>
Is anything wrong with the XML generated for custom exceptions in the detail
element.
many thanks,
--
--gaurav