Using custom DataContractResolver in WCF, to transport inheritance trees involving generics
- by Benson
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:
Are DataContractResolvers typically only used on the service side, and not by the client? If so, how would that be useful in this scenario?
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?