Daniel Robinson
Daniel Robinson

Reputation: 14898

WCF service contract(s) design

I want to make my first WCF service but I am unsure of how to structure it.

the serivce will take requests to retrieve different types of items from my database:

List<Product> getProducts()
List<Module> getModules(Product)
List<Releases> getReleases(Product)
List<Feature> getFeatures(Product,Module)
//many more types of items to get etc...
//and then the equivalent functions to update those item types back in the database...

So should I implement all of this as a single service contract?

[ServiceContract]
public interface IMyService{}

public class MyService : IMyService{}

I understand this way I would only have to host one service but could this become bogged down with heavy traffic trying to serve lots of people all the possible requests they could make?

or should I have a different service contract for each type of item and have each one implemented separately so I could host each of them on separate machines to reduce poor performance from possible times of heavy traffic?

[ServiceContract]
public interface IMyProductService{}
public class MyProductService : IMyProductService{}

[ServiceContract]
public interface IMyModuleService{}
public class MyModuleService : IMyModuleService{}

[ServiceContract]
public interface IMyUserService{}
public class MyUserService : IMyUserService{}

... etc etc ...

Upvotes: 0

Views: 155

Answers (1)

Chris
Chris

Reputation: 2481

I would have the single implementation of all the contracts. Something like:

public interface IUserService{}
public interface IYourModuleService{}
public interface IYourProductService{}
    public class YourService : IUserService, IYourModuleService, IYourProductService{}

That way you can also control your clients only use the contracts they need, but also (unless youre expecting massive volume)your implementation design should be the first port of call for any bottle necks, rather than contract design.

Also you can use all of the WCF Tools 'out of the box' to control volume and instances and so on - to streamline your processes.

So in short - single implementation, multiple service contracts.

Upvotes: 1

Related Questions