Is it possible to pass generic objects (by generic I mean any with DataContract
, not C# generic collection) without inheriting from one root? At the moment I have something like this:
[OperationContract]
void Save(GenericObject o);
[DataContract]
[KnownType(typeof(ClassA))]
[KnownType(typeof(ClassB))]
class GenericObject {....
[DataContract]
class ClassA: GenericObject {....
[DataContract]
class ClassB: GenericObject {....
Everything was OK, but the project has got bigger and I cannot really afford to derive all those contracts from one class.
I don't want to add specialized methods to the service. As a workaround I can manually serialized classes to string or byte[] via DataContractSerializer and deserialized them on the server side: void Save(byte[] serializedObject) but that's a bit of a hack.
I've noticed that I can easily return generic objects e.g. object Load(string id) works just fine, but void Save(object o) does not.
I'm using Silverlight as a client.