473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Deserialize Object contained in Fault Detail Element of SoapExcept

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 both SoapFormatter, and XmlSerializer with absolutely no luck.

try
{
<<<< e.g. login operation >>>>
}
catch (System.Web.Services.Protocols.SoapException e)
{
XmlReader reader = null;
XmlWriter writer = null;
MemoryStream mem = new MemoryStream();
FdkException fe = null;

try
{
reader = new XmlNodeReader(e.Detail.FirstChild);
writer = new XmlTextWriter(mem, System.Text.Encoding.UTF8);
writer.WriteNode(reader,true);
writer.Flush();
mem.Position = 0;

<<<< Add deserialization code here >>>>
fe = (FdkException) ....
}
catch (Exception ex)
{
System.Console.WriteLine(ex.toString());
throw;
}
}

The first deserialization mechansim I tried was using
System.Runtime.Serialization.Formatters.Soap.SoapF ormatter

SoapFormatter sf = new SoapFormatter();
sf.Binder = new FdkExceptionDeserializationBinder();
fe = (FdkException) sf.Deserialize(mem);

With FdkExceptionDeserializationBinder.cs looking like the following:

public class FdkExceptionDeserializationBinder :
System.Runtime.Serialization.SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
if (assemblyName.Equals(http://xmlns.mycompany.com/app/ws))
{
switch (typeName)
{
case FdkException : return typeof(FdkException); break;
case ArrayOfFdkExceptionEntry : return typeof(FdkExceptionEntry[]);
break;
}
}
return Type.GetType(String.Format({0}, {1}, typeName, assemblyName));
}
}

This deserialization approach resulted in an exception:
Exception Type: System.Runtime.Serialization.SerializationExceptio n
Message: No Top Object
Source: System.Runtime.Serialization.Formatters.Soap
The second deserialization mechanism I tried was using XmlSerializer:
XmlTypeMapping myMapping = (new
SoapReflectionImporter().ImportTypeMapping(typeof( FdkException)));
XmlSerializer serializer = new XmlSerializer(myMapping);
fe = (FdkException) serializer.Deserialize(mem);

I tried settign SOAP options in the .NET genererated FdkException class such
as the following before the class

definition:

I set SoapType options in the FdkException class:
using System;
using System.Xml.Serialization;
....
[Serializable]
[SoapTypeAttribute(Namespace="http://xmlns.mycompany.com/app/ws",
TypeName=fault)]
public class FdkException
{
public string errorCode;
public FdkExceptionEntry[] exceptionEntries;
public string serverStackTraceId;
}
using System;
using System.Xml.Serialization;
[Serializable]
[SoapTypeAttribute(Namespace="http://xmlns.mycompany.com/app/ws",
TypeName=FdkExceptionEntry)]
public class FdkExceptionEntry
{
public string errorCode;
public long id;
public string serverStackTraceId;
}
I got the following exception:
Message: There is an error in XML Document (1,541).
Exception Type: System.InvalidOperationException
Source: System.Xml

Inner Exception:
Message: Cannot assign object of type System.Xml.XmlNode[] to an object of
type FdkException
Exception Type: System.InvalidCastException

Below is the SOAP message returned from the server on an invalid logon
attempt (including Fault):-
<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>AccessDenied</faultstring>
<detail>
<ns1:fault xsi:type="ns1:FdkException"

xmlns:ns1="http://xmlns.mycompany.com/app/ws">
<errorCode xsi:type="soapenc:string"

xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">AccessDenied -
Invalid Credentials</errorCode>
<exceptionEntries xsi:type="ns1:ArrayOfFdkExceptionEntry"

xsi:nil="true"/>
<serverStackTraceId xsi:type="soapenc:string"

xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
</ns1:fault>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>


Below is pieces of the WSDL file ripped out relating to the FdkException
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://xmlns.mycompany.com/app/ws">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="FdkExceptionEntry">
<sequence>
<element name="errorCode" nillable="true" type="xsd:string"/>
<element name="id" type="xsd:long"/>
<element name="serverStackTraceId" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="ArrayOfFdkExceptionEntry">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType"

wsdl:arrayType="impl:FdkExceptionEntry[]"/>
</restriction>
</complexContent>
</complexType>
<complexType name="FdkException">
<sequence>
<element name="errorCode" nillable="true" type="xsd:string"/>
<element name="exceptionEntries" nillable="true"

type="impl:ArrayOfFdkExceptionEntry"/>
<element name="serverStackTraceId" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</schema>
</wsdl:types>

<wsdl:message name="FdkException">
<wsdl:part name="fault" type="impl:FdkException"/>
</wsdl:message>

<wsdl:portType name="RemoteLoginManager">
<wsdl:operation name="login" parameterOrder="username password options
userAttributes">
<wsdl:input name="loginRequest" message="impl:loginRequest"/>
<wsdl:output name="loginResponse" message="impl:loginResponse"/>
<wsdl:fault name="FdkException" message="impl:FdkException"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="RemoteLoginManagerSoapBinding"
type="impl:RemoteLoginManager">
<wsdlsoap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="login">
<wsdlsoap:operation/>
<wsdl:input>
<wsdlsoap:body use="encoded"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://xmlns.mycompany.com/app/ws"/>
</wsdl:input>
<wsdl:output>
<wsdlsoap:body use="encoded"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://xmlns.mycompany.com/app/ws"/>
</wsdl:output>
<wsdl:fault name="FdkException">
<wsdlsoap:fault name="FdkException" use="encoded"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://xmlns.mycompany.com/app/ws"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
Has anyone out there been able to deserialize from SOAP fault detail element?
many thanks,

Matt.
Nov 23 '05 #1
0 4056

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Miha Valencic | last post by:
Hi! WS is written in java in I am consuming it with .net (v1.1) client. The problem is in Soap fault exception (below). The program returns exception: Unhandled Exception:...
0
by: cullepm3 | last post by:
I would like to convert the xml fault information in SoapException.Detail into a class. The webservice that I am connecting defines a type called WebServiceException. All the methods provided by...
4
by: Samuel R. Neff | last post by:
I'm deserializing an XML file. If I pass a Stream to the file directly to the deserializer as follows it works fine: o = (New XmlSerializer( GetType(...
3
by: Jeff Richardson | last post by:
This is a repost from the InfoPath news group. Hi, I am writing a SharePoint application that works with InfoPath forms. When a user submits a completed InfoPath form to a forms library my code...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
2
by: Thomas S | last post by:
Any suggestions on how to deserialize an object from one line of XML? I'm trying to deserialize multiple objects from one XML document, each object on one line of the file. The serialization is...
6
by: Redowl | last post by:
Hi, I am having an issue deserializing a business object from a SQL stored procedure. I have created the class using the XSD tool and the resulting XMLDATA schema but when I try to create the...
9
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hi, I have a schema that has an optional element, fieldTag4000Field. If the element is omitted from the XML request, when it is deserialized, it will be null when I check it - which is fine. ...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.