Using custom DataContractResolver in WCF, to transport inheritance trees involving generics

Posted by Benson on Stack Overflow See other posts from Stack Overflow or by Benson
Published on 2010-03-13T11:21:21Z Indexed on 2010/03/13 11:25 UTC
Read the original article Hit count: 2322

Filed under:
|
|
|

I've got a WCF service, in which there are operations which accept a non-generic base class as parameter.

[DataContract] class Foo { ... }

This base class is in turn inherited, by such generics classes as

[DataContract] class Bar : Foo { ... }

To get this to work, I'd previously have to register KnownTypes for the Foo class, and have these include all possible variations of Bar (such as Bar, Bar and even Bar>).

With the DataContractResolver in .NET 4, however, I should be able to build a resolver which properly stores (and restores) the classes.

My questions:

  1. Are DataContractResolvers typically only used on the service side, and not by the client? If so, how would that be useful in this scenario?

  2. Am I wrong to write a DataContractResolver which serializes the fully qualified type name of a generic type, such as Bar1[List1[string, mscorlib], mscorlib] ? Couldn't the same DataContractResolver on the client side restore these types?

© Stack Overflow or respective owner

Related posts about wcf

Related posts about .NET