473,396 Members | 2,037 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,396 software developers and data experts.

adding namespaces to XmlSerializer when deserializing (C#)

Hi there
I'm hoping there's an easy answer to a (hopefully) not too long-winded issue...
I'm building a C# web client using a proxy wsdl.exe'd from a wsdl file and six schemas, each in a different namespace. Some schemas extend complex types in others. When i get a soap:Fault from my test server it could contain a serialized exception object (called fault) from one of two of these schemas (and different namespaces, call them xmlns:b0="ns1" and xmlns:eb="ns2"), yet the root element of the SoapException.Detail node will remain the same (in "ns1"). The prefix declaration is in the soap:Fault node of the response.

Now, if the object i'm trying to desrialize is defined in the same schema as the root element <b0:faultResp> (e.g. <b0:fault xsi:type="b0:ThisEx">) i create an XmlSerializer with this default namespace and it deserializes no problem, and the root element of the Detail node becomes <b0:faultResp xmlns:b0="ns1">. If it's defined in the other schema (e.g. <b0:fault xsi:type="eb:ThatEx">). i get an error: "Namespace prefix 'eb' is not declared", yet both prefixes are defined in the <soap:Fault xmlns:b0="ns1" xmlns:eb="ns2"> node

I understand that XmlSerializer.Serialize method takes an XmlNamespaces parameter which allows you to add any other namespaces it needs when serializing, but XmlSerializer.Desrialize doesn't; i can't find any way to at all. SoapFormatter.deserialize didn't work nor did using XmlSerializerFactory to create the serializer. So my questions then:

1. Is there some way to specify additional namespaces (like that xmlns:eb="ns2" guy) to the XmlSerializer object before deserializing?
2. Is there a way to extract the namespace declarations in the soap:Fault node from the SoapException the webmethod catches?
3. Is there a way of doing this without worrying about the namespaces at all?
4. Is there an easier way of explaining this?

The Fiddler'd response looks like this:
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<soap:Fault xmlns:b0="ns1" xmlns:eb="ns2" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<faultcode xmlns="">soap:Server</faultcode>
<faultstring xmlns="">An exception was thrown on the server/faultstring>
<detail xmlns="">
<b0:faultResp>
<b0:fault xsi:type="eb:ThatEx">
<b0:desc>That other exception occurred</b0:desc>
</b0:fault>
</b0:faultResp>
</detail>
</soap:Fault>
</Body>
</Envelope>


Excerpt from schema 1 (xmlns:b0="ns1")

<element name="faultResp" type="i0:FaultResp">
<annotation>
<documentation>A fault.</documentation>
</annotation>
</element>
<complexType name="faultResp">
<annotation>
<documentation>A fault.</documentation>
</annotation>
<complexContent>
<extension base="i0:BaseResp">
<sequence>
<element minOccurs="1" maxOccurs="1" name="fault" type="i0:Fault"/>
</sequence>
</extension>
</complexContent>
</complexType>
...
<complexType name="Fault" abstract="true">
<annotation>
<documentation>A generic fault.</documentation>
</annotation>
<sequence>
<element minOccurs="1" maxOccurs="1" name="desc" type="i0:Msg">
<annotation>
<documentation>description of the fault</documentation>
</annotation>
</element>
</sequence>
</complexType>

Excerpt from schema 2 (xmlns:eb="ns2")

<complexType name="ThatEx">
<annotation>
<documentation>That Other exception.</documentation>
</annotation>
<complexContent>
<extension base="b0:Fault" />
</complexContent>
</complexType>

What I'm looking for is to deserialize the <b0:faultResp> into an object of type FaultResp, with a property of type ThatEx, that has a string property called desc.

Any help appreciated.
Dave
Nov 21 '07 #1
0 2774

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
4
by: Alexis | last post by:
Hello, Is there a way of telling the XmlSerializer to ignore all namespaces when deserializing. I'm using XmlAttributeOverrides, but I have to do it for every class the OutputObject usses. Is...
3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
0
by: Bluetears76 | last post by:
Now Hierarchy is that there is a class named "Student" There are two child classes "GraduateStudent" and "HighSchoolStudent". I worte the following code for serializing the student and...
4
by: BuddyWork | last post by:
Hello, When running the following line of code XmlSerializer serializer = new XmlSerializer(typeof (MyXmlTestClass)); I get the following exception message. An unhandled exception of
3
by: rdcpro | last post by:
Hi all, I've been building a nifty deserializing configuration handler that I use in conjunction with my web.config in an ASP.NET web app. This is working quite well, but I'm planning on...
1
by: Keith Patrick | last post by:
I have an object, Teacher, that has a namespace. Let's call it http://foo. Teacher has a child object called Name, composed of String first, middle, last, etc. Problem I have is when I try to...
0
by: Joel Moore | last post by:
We have an app that currently uses SOAP for a data file format. It works well enuogh but I would prefer an XML format that's a little friendlier to the human eye. I had started looking at...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.