DataContract serialization exception (data contract name is not expected)

感情迁移 提交于 2019-11-30 04:38:02

Add this line:

 [KnownType(typeof(TestContract))]

So that

[Serializable]
[KnownType(typeof(TestContract))]
public class DNCJsonDictionary<K, V> : ...

This is a known issue. That is why generics does not quite work with WCF.

But the reason is easy, WCF is supposed to create WSDL and be able to publish your contract. It is all well and good to use Generics to define your contract but WSDL needs to point to some concrete class hence you need KnownType.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!