How to pass a shared object through WCF

Is it possible to pass shared objects (by default I mean any with DataContract

, not a C # collection) without inheriting from a single 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 fine, but the project got bigger and I can't afford to get all these contracts from one class.

I don't want to add specialized methods to the service. As a workaround, I can manually serialize the classes to string or byte [] using the DataContractSerializer and deserialize them on the server side: void Save (byte [] serializedObject), but this is a bit of a hack.

I noticed that I can easily return generic objects for example. the Load object (row id) works just fine, but void Save (o object) doesn't.

I am using Silverlight as a client.

0


a source to share


1 answer


Yes, you can use a generic type Message

for WCF projects, which can be anything, in fact. However, this puts a lot of work on you, both on the client side creating the message object (basically you have to manually create the XML that makes up the general message) and on the server side as you cannot rely on good serialization / deserialization XML. You are dealing with basic, raw corner soup (straight XML).

It works and it might be a solution, but maybe there are other more elegant and useful solutions? Is this inheritance really necessary? Think about your system design.



Mark

+1


a source







All Articles