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.Ser vices.Protocols .SoapException e)
{
try
{
System.Xml.Seri alization.XmlSe rializer ser=
new System.Xml.Seri alization.XmlSe rializer(typeof
(FdkException)) ;
System.IO.Strin gReader sr= new
System.IO.Strin gReader(e.Detai l.InnerXml);
FdkException fault= (FdkException) ser.Deserialize (new
System.Xml.XmlT extReader(sr));
FdkException fault= (FdkException) ser.Deserialize (new
System.Xml.XmlT extReader(strea m));
}
catch (Exception ex)
{
System.Console. WriteLine(ex.to String());
throw;
}
}
I set SoapType options in the FdkException class(generated through wsdl) as
mentioned in the mailing list
....
[Serializable]
[System.Xml.Seri alization.XmlTy pe("Fault",
Namespace="http ://xmlns.mycompany .com/content/ws")]
[System.Xml.Seri alization.XmlRo ot("Fault",
Namespace="http ://xmlns.mycompany .com/content/ws")]
[System.Xml.Seri alization.SoapT ypeAttribute("F dkException",
"http://xmlns.mycompany .com/content/ws")]
public class FdkException
{
public string errorCode;
public FdkExceptionEnt ry[] exceptionEntrie s;
public string serverStackTrac eId;
}
[Serializable]
[SoapTypeAttribu te(“FdkExcept ionEntry”,"ht tp://xmlns.mycompany .com/app/ws")]
public class FdkExceptionEnt ry
{
public string errorCode;
public long id;
public string serverStackTrac eId;
}
This deserialization approach resulted in an exception:
Exception Type: System.InvalidO perationExcepti on
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:En velope
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"><soap env:Body>
<soapenv:Fault> <faultcode>soap env:Server.user Exception</faultcode><faul tstring>MYCOMPA NY.FDK.Aggregat eError: MYCOMPANY.FDK.A ggregateError</faultstring>
<detail> =====>> This is what we are tying to deserialise to
FdkException
<ns1:fault xsi:type="ns1:F dkException"
xmlns:ns1="http ://xmlns.mycompany .com/content/ws"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<exceptionEntri es soapenc:arrayTy pe="ns1:FdkExce ptionEntry[1]"
xsi:type="soape nc:Array"
xmlns:soapenc=" http://schemas.xmlsoap .org/soap/encoding/">
<exceptionEntri es xsi:type="ns1:F dkExceptionEntr y">
<detailedErrorC ode
xsi:type="xsd:s tring">MYCOMPAN Y.FDK.ServerErr or</detailedErrorCo de>
<errorCode
xsi:type="xsd:s tring">MYCOMPAN Y.FDK.Unexpecte dError</errorCode>
<id xsi:type="xsd:l ong">0</id>
<serverStackTra ceId
xsi:type="xsd:s tring">22-1132729995032</serverStackTrac eId>
</exceptionEntrie s>
</exceptionEntrie s>
<detailedErrorC ode
xsi:type="xsd:s tring">MYCOMPAN Y.FDK.Aggregate Error</detailedErrorCo de>
<errorCode
xsi:type="xsd:s tring">MYCOMPAN Y.FDK.Aggregate Error</errorCode>
<serverStackTra ceId xsi:type="xsd:s tring"></serverStackTrac eId>
</ns1:fault>
</detail>
</soapenv:Fault></soapenv:Body></soapenv:Envelop e>
Is anything wrong with the XML generated for custom exceptions in the detail
element.
many thanks,
--
--gaurav