tags:

views:

29

answers:

2

If I have a service contract containing 2 operations, is it possible to have a client side service contract (.NET interface) that only has one of those operations? More generally, is it possible to only use a subset of service operations on the client and even to not have to have generated code for other operations (and their corresponding data contracts)?

A: 

The proper way to do this is to create a new OperationContract that contains only the method you wish to expose and then bind that OperationContract to a new endpoint and expose that endpoint to your client.

Andrew Hare
+1  A: 

Yes, it's definitely possible. Since you mention generated code, I'm guessing that you're using service references in Visual Studio. If so, you can simply edit the generated interfaces and classes to omit the operations you wish to exclude. However, you will need to perform this edit each time you update the service reference in your client project, so it's probably not an approach you would want to adopt unless the service interface is not expected to change.

Regardless of how often the service might change, a somewhat more elegant approach would involve creating your own adapter with which all your service client code can interact.

Nicole Calinoiu
I have my own client code generator (similar to the SvcUtil). I will just add an option to exculde some operations of the service contract when generating service reference. Thank you very much for such a quick response.
Nikola