Serialising soap faults



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("FdkException",
"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.userException</faultcode><faultstring>MYCOMPANY.FDK.AggregateError: 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.UnexpectedError</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
.



Relevant Pages

  • Deserialize Object contained in Fault Detail Element of SoapExcept
    ... I'm trying to build a C# client to consume an AXIS Web Service (running SOAP ... full server-side exception traces in the Soap Fault> Detail element using ... fe = (FdkException) sf.Deserialize; ... Below is the SOAP message returned from the server on an invalid logon ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Soap Faults
    ... I'm trying to build a C# client to consume an AXIS Web Service (running SOAP ... The Web Service encodes full server-side exception traces in the ... FdkException fault= ser.Deserialize(new ... Below is the SOAP message returned from the server on an invalid operation ...
    (microsoft.public.dotnet.framework.webservices)
  • RE: Backup & Monitoring not working!
    ... Error message in Windows Small Business Server 2003: ... Microsoft CSS Online Newsgroup Support ... This newsgroup only focuses on SBS technical issues. ... An unhandled exception occurred during the execution of the ...
    (microsoft.public.windows.server.sbs)
  • Re: Sharepoint 2007 - Installation Error - Failed to register SP s
    ... Windows 2000 Server. ... It is a bug with Beta 2 where the database server is running Windows 2000. ... Server I have the following exception: ... RunBehavior runBehavior, String resetOptionsString) ...
    (microsoft.public.sharepoint.portalserver)
  • return from server only works for built-in types
    ... But when I call _r.GetStatisticsthe client fails with the exception shown ... GetStatistics fails when client and server is on different networks. ... Win32 Version: 2.0.50727.832 ...
    (microsoft.public.dotnet.framework.remoting)

Quantcast