问题
I keep running into namespace mismatches when trying to deserialize the SOAP response.
The response is unqualified and the nested complex types are qualified with a namespace like this:
<getResult>
<enc:ApplicationExceptionOccurred xmlns:enc="com.namespace1.www/complexTypes">false</enc:ApplicationExceptionOccurred>
<enc:SystemExceptionOccurred xmlns:enc="com.namespace1.www/complexTypes">false</enc:SystemExceptionOccurred>
<enc:ComplexType xmlns:enc="com.namespace1.www/complexTypes">
...
</enc:ComplexType>
</getResult>
I can get the namespaces correct by adding the following attribute to the generated types:
[System.Xml.Serialization.XmlElementAttribute(Namespace="com.namespace1.www/complexTypes", Form=System.Xml.Schema.XmlSchemaForm.Qualified, Order=0)]
This works fine if the message is Literal. However, this service uses SOAP encoding. When I add the following to the XmlSerializerFormatAttribute:
Use = System.ServiceModel.OperationFormatUse.Encoded
Then the XmlElementAttributes appear to be ignored and I once again have namespace mismatch issues. I presume that I need to use the SoapElementAttribute instead, but it does not have a way to set the namespace.
So...How can I set the namespace in a manner similar to XmlElementAttribute on Soap encoded messages?
来源:https://stackoverflow.com/questions/7840665/wcf-client-soap-encoding-complex-types-in-different-namespace