XML Fault serialization fails if an xsi:type contains a schema identifier
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
If the server replies with the following SOAP fault:
```xml
ServerFaultCode
The resource 'Storage1' is in use.
...
name
Storage1
reason
vmsRegistered
...
Storage1
```
the client fault serialization would fail with the error:
Namespace prefix 'xsd' is not defined.
```
at System.Xml.Serialization.XmlSerializationReader.ToXmlQualifiedName(String value, Boolean decodeName)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderResourceInUse.Read1_Object(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderResourceInUse.Read4_KeyAnyValue(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderResourceInUse.Read5_LocalizableMessage(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderResourceInUse.Read8_ResourceInUse(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderResourceInUse.Read9_ResourceInUseFault()
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.ServiceModel.Dispatcher.XmlSerializerObjectSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
at System.ServiceModel.Dispatcher.XmlSerializerFaultFormatter.CreateFaultException(MessageFault messageFault, String action)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
```
The value element is defined in the xsd schema as:
```xml
```
Looking at the code generated for the deserializer, I am under the impression that the deserializer would try to read the xsi:type attribute to determine the actual type. In this case the value of the xsi:type is "xsd:string", where xsd is defined at the root element of the SOAP envelope.
I think this is the expected behavior.
I think that then the call to ToXmlQualifiedName on the "xsd:string" value fails because the reader does not have a definition for the xsd namespace.
Looking at the code of the MessageFault.GetReaderAtDetailContents, it looks like the fault details element is copied to a buffer and a reader for that buffer is returned.
The issue is probably that this way the schema definitions of the original xml reader are lost if those namespaces are not present in the xml fragment that is being extracted.
To summarize,
The xml SOAP response is correct, but the WCF fault deserializer fails to deserialize the fault details. (Probably due to losing the schema definitions information.)
Contributor guide
Assessment
This issue has not been assessed yet.