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 methods, 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?
Definition of an Endpoint Address. In WCF, an EndpointAddress models an endpoint reference (EPR) as defined in the WS-Addressing standard.
WCF formalizes this relationship in the form of an endpoint. The endpoint is the fusion of the address, contract, and binding (see Figure 1-8). Every endpoint must have all three elements, and the host exposes the endpoint. Logically, the endpoint is the service's interface and is analogous to a CLR or COM interface.
Endpoints provide clients access to the functionality offered by a WCF service. Each endpoint consists of four properties: An address that indicates where the endpoint can be found. A binding that specifies how a client can communicate with the endpoint. A contract that identifies the operations available.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With