The "gxNgnmsk" at the end of <d3p1:KeyValuePairOfStringDatagxNgnmsk>
is the cause of your problem. The presence of this suffix is explained in Data Contract Names for Generic Types:
Special rules exist for determining data contract names for generic types...
By default, the data contract name for a generic type is the name of the type, followed by the string "Of", followed by the data contract names of the generic parameters, followed by a hash computed using the data contract namespaces of the generic parameters. ... When all of the generic parameters are primitive types, the hash is omitted.
The "gxNgnmsk"
is the hash. And if I use your classes to generate XML from instances created in memory, I get a different hash:
<Stamdata xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/a">
<Liste xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<d2p1:KeyValuePairOfstringDatatwCi8m_S7>
<d2p1:key>key value</d2p1:key>
<d2p1:value />
</d2p1:KeyValuePairOfstringDatatwCi8m_S7>
</Liste>
</Stamdata>
Apparently your Data
type does not have the correct data contract namespace, causing an inconsistent hash to get generated. (And, from experiment, neither "http://schemas.datacontract.org/2004/07/System.Collections.Generic"
nor "http://schemas.datacontract.org/2004/07/a"
nor ""
seem to generate the correct hash. Possibly I could guess the correct namespace from a complete XML sample, but there's not enough information in the simplified XML provided.)
So, what can be done to fix this?
You could get the "one behind the response" to tell you the correct data contract name and namespace for all contract types including Data
. This is necessary anyway for data contract equivalence when sending data over the wire so they should be able to provide this information.
If the "one behind the response" provides a WSDL (and they should) you should be able to auto-generate a client which should just work.
But in the absence of the above, you can work around the problem by creating a collection with a custom collection data contract with the hash baked in:
[DataContract(Name = "Stamdata", Namespace = "http://schemas.datacontract.org/2004/07/a")]
public class Stamdata
{
[DataMember]
public DataList Liste { get; set; }
}
[CollectionDataContract(
Namespace = "http://schemas.datacontract.org/2004/07/System.Collections.Generic",
ItemName = "KeyValuePairOfStringDatagxNgnmsk")]
public class DataList : List<KeyValuePair<string, Data>>
{
public DataList() : base() { }
public DataList(IEnumerable<KeyValuePair<string, Data>> list) : base(list) { }
}
With this version of Stamdata
the sample XML can be deserialized without knowing the correct namespace for Data
.