tags:

views:

30

answers:

1

I've got a WCF service with lots of method and DataContracts. It is usually consumed by large application "A". I want to create a tiny application "B" which will use the very same server but only a few methods from the service. I want to reduce the size of the XAP, and since the client is using a fraction of all methods exposed by the service, I'd like to have a smaller service reference file than the one automatically created by Visual Studio. I can remove methods which are not used manually but then I cannot really use update service command.

Any solutions?

Many thanks, Karol

+1  A: 

OK, so you have a complete IGreatService interface with lots of methods, which are implemented on a MyGreatService class.

How about this: you create a new, second interface IMyServiceB which has only those few methods you want to expose to the second group of users. You make it so your service implements both IGreatService and IMyServiceB (that's absolutely possible, no problem):

public class MyGreatService : IGreatService, IMyServiceB
{
 .. 
}

Service B basically then just calls those few methods in the service implementation that you want to expose - let's say, you have MethodA on IGreatService that you want to expose on IMyServiceB as well (as MethodB) - implement it like that:

public class MyGreatService : IGreatService, IMyServiceB
{
   ....
   // as defined on IGreatService
   public void MethodA (....)  
   {
   }

   ....
   public void MethodB (.....)   // as defined on IMyServiceB
   {
        MethodA();
   } 
}

That way, you get two separate interfaces (= services), but basically you write your code only once.

You can then expose IMyServiceB on a distinct and separate endpoint, so that users who are supposed to only see IMyServiceB can just connect to that separate endpoint, and they'll only get whatever they need to use your service-B operations.

Could that work?

Marc

marc_s
Hi Marc, it works pretty well. I didn't use the same service, since it's implemented as a singleton but rather created the second service which acts like a proxy, but still it solved my problem.
Karol Kolenda