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:
<soap:Fault xmlns:b0="ns1" xmlns:eb="ns2" xmlnsoap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<faultstring xmlns="">An exception was thrown on the server/faultstring>
<b0esc>That other exception occurred</b0esc>
Excerpt from schema 1 (xmlns:b0="ns1")
<element name="faultResp" type="i0:FaultResp">
<element minOccurs="1" maxOccurs="1" name="fault" type="i0:Fault"/>
<complexType name="Fault" abstract="true">
<documentation>A generic fault.</documentation>
<element minOccurs="1" maxOccurs="1" name="desc" type="i0:Msg">
<documentation>description of the fault</documentation>
Excerpt from schema 2 (xmlns:eb="ns2")
<documentation>That Other exception.</documentation>
<extension base="b0:Fault" />
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.
DaveWednesday, November 21, 2007 12:10 PM
Could you provide more details on how you resolved it? I'm running into problems deserializing xml that contains namespace prefixes. Without the prefix I'm able to deserialize fine - I just can't figure out how to deserialize WITH the prefix.
...running out of patience...
Any help would be greatly appreciated!Tuesday, April 21, 2009 9:34 PM
That is a horrible answer, that negates the fact that the original poster came in with a question searching for proper answers. In the spirit of the community, he should post his resolution for anyone else that is a similar situation instead of being selfish. The community works both ways, giving and receiving.Saturday, December 22, 2012 7:56 PM
I'm sorry, but I have no idea who you are responding to.
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service ProjectsMonday, December 24, 2012 5:31 PM