views:

51

answers:

3

I have a wcf service that exposes quite a large number of service methods on a single endpoint address. Up to now, all service methods are implemented in a single service contract class. This service contract class implements several service contract interfaces. Now I would like to split the implementation of of the service contract methods into several classes in order to avoid the contract class from growing to big. I use a self hosting scenario with a ServiceHost. The ServiceHost just takes the type of one single type implementing the service mehtods, so it seems that everything has to be implemented in this class. Of course the flesh of the methods can be factored out into several classes. But is there also a way to split the methods into several classes?

A: 

You can implement the service as a partial class, which lets you split the implementation to multiple files.

If the requirement is to keep a single endpoint and a single interface, then there is no other way of splitting it up - the one class you create must implement all of the interface.

I would suggest to keep the service implementation as simple as possible, and just have each method be a one-liner that delegates the operation to the actual implementation, which can then be split over multiple classes. Perhaps it would even make sense to make one per operation ? That is a pattern I have used before with success.

driis
Thank you for your reply. I also thought about partial classes, but in my opinion partial classes do not help to keep a solution simple. I will go as you suggested, using a one liner for every operation
WalterOesch
A: 

You can create as many Service contracts as you desire, each with its own logic behind it.

The up-side of this approach is, as it seems you desire, to logically group together related functions.

The down-side is that the calling client must now know which service to use when calling the function.

aaaa bbbb
A: 

It is good approach to limit number of operations in the service. As I understand your scenario at the moment you have single service implementation which implements several service contracts. This means that you already have multiple endpoints on your service - each enpoint exposes single contract. In that case your client is already prepared to create separate proxy for each needed contract.

Now you want to divide your service implementation class in multiple service implementations. Each service implementation will implement one (or smaller set) of service contracts. This will require modification of your hosting application - you will need separate ServiceHost for each service implementation. You will also need separate configuration and unique address for each service implementation.

Client side can be just recreated with new services but I think it should also be possible to simply change addresses for endpoints and it should work.

Ladislav Mrnka
Thank you for your reply. I am currently planning and implementing a data exchange interface for a quite large system. Clients will most probably always use the entire interface an may run of different platforms. In such a szenario I think it is easiest for the client to have just a single endpoint address. I created several service contract interfaces and let a "Master Interface" inherit from all service contract interfaces. The servcice contract class then implements the master interface.
WalterOesch