views:

1063

answers:

3

hi there,

i have a library with some entities that share the same interface. clients and service share this assembly. now i wonder if there is a way to have this Interface-type as Parameter in my service contracts so that i can use the same method for all classes implementing the interface.

the entities themselve are all decorated with datacontract-attribute and its members with datamember attributes.

is it possible at all? probably with the NetDataContractSerializer? i know that i can do it with a base class (some abstract class e.g.) and the knowntype-attribute but i´d definitely prefer the Interface as identificator of the objects cause it is used widely in the client app and would ease development.

thanks

+1  A: 

It certainly isn't possible under regular "mex". It might be possible with assembly sharing, but I really wouldn't recommend it - you are fighting WCF: it will be brittle, etc. Of course, you can always mask this in your object model - i.e. rather than calling the [OperationContract] method directly, abstract this away into a wrapper method that hides the WCF details (perhaps using different objects for the data transfer than it actually returns).

Marc Gravell
+3  A: 

hi there,

i solved the problem using the ServiceKnownType attribute at the implementations of the operationcontracts. when telling your classes that implement the interface as ServiceKnownType's, you can use the interface as parameter ans therefore are able to use all classes implementing your interface as long as they are serializable. (look at "Programming WCF Services" from Juval Löwy, page 100)

Joachim Kerschbaumer
A: 
Wayne