WCF issues with KnownType for Dictionary

Posted by Tom Frey on Stack Overflow See other posts from Stack Overflow or by Tom Frey
Published on 2010-06-09T22:35:45Z Indexed on 2010/06/09 22:42 UTC
Read the original article Hit count: 363

Filed under:
|
|

Hi,

I have a service that implements the following DataMember:

[DataMember]
public Dictionary<string, List<IOptionQueryResult>> QueryResultItems { get; set; }

I have the class "OptionQuerySingleResult" which inherits from IOptionQueryResult. Now, I understand that I need to make the OptionQueryResult type "known" to the Service and thus tried to add the KnownType in various ways:

[KnownType(typeof(Dictionary<string, OptionQuerySingleResult[]>))]
[KnownType(typeof(Dictionary<string, List<OptionQuerySingleResult>>))]
[KnownType(typeof(OptionQuerySingleResult)]

However, none of those approaches worked and on the client side I'm either getting that deserialization failed or the server simply aborted the request, causing a connection aborted error.

Does anyone have an idea on what's the proper way to get this to work? I'd like to add, the if I change the QueryResultItems definition to use the concrete type, instead of the interface, everything works just fine.

Thanks,

Tom

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf