Could I please get some clarification on a complex WCF service that exposes my business objects. Let’s say I have 4 objects: contact, organisation, project and letter.
Is the best way to create my service:
- Make 4 contracts as ‘service objects’ and pass the object and the intended operation as values/parameters in the ‘service object’? or
- Create contracts for all of the objects and their functions (which could be many)?
Many Thanks,
Chris
According to the Interface Segregation Principle, you might want to think about splitting those things up.
One typical approach is to have one interface (e.g. one “service”) per object type – e.g. one interface for
Contactwith all the operations needed and useful for contacts, etc.Of course, you might also have methods that deal with multiple different types of objects – those are a bit tricky to place in a specific service contract.
Also, with WCF, you can easily have a single service implementation class that then in turn implements multiple of those interfaces at once – e.g. to use common code or common patterns.
But I guess it would be a good idea to rethink your service contract and convert it into smaller, more manageable chunks.
Update:
if your service implementation class implements four service contracts, then you’d have to configure it like this:
Now, each of your services is available at a specific endpoint:
IContractServiceis reachable athttp://YourServer/MyServices/ContactILetterServiceis reachable athttp://YourServer/MyServices/Letterand so on….
For each of those addresses, you can now add service references from a client – add only those you really need. One app might need only a single of those services, another might need two or three etc.