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?

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

I am calling the c# webservice which has Soap Authentication. The Soap Envelope inside which the Soap Header is present contains the attribute xmlns:types.
this attribute is not coming in my webservice.
I want to know how can we add this attribute in my webservice.

This article has been dead for over six months. Start a new discussion instead.