问题描述:

Is it ok to have a 200 methods in a single WCF service? I can not avoid that it is just big service. Is it not a good practice and how to deal with it if it isn't ok?

网友答案:

I dont see any problem in having 200 methods in a service, but seems to me a bad design.

You can categorize on any relevant thing to keep in different class. Is it like all the 200 methods are availabe to everybody and in one go and you dont want to put some SOC ?

网友答案:

This is a problem of service composition. 200 service operations = high granularity. What are your operation names? I'm guessing, but I bet they are like:

  • InsertTypeA (TypeA typeA)
  • InsertTypeB (TypeB typeB)
  • UpdateTypeA (TypeA oldTypeA, TypeA newTypeA)
  • DeleteTypeB (int typeBId)
  • etc..

What you need to think about is what business events is the service facilitating? So a business event would be something like:

  • Product added to catalogue
  • Account merged with child account
  • Invoice issued to customer
  • etc

So your service operations should reflect your business events:

  • AddProductToCatalogue (int productId, int catalogueId)
  • MergeAccounts (int accountId, int childAccountId)
  • IssueInvoice (int customerId)
  • etc

By focusing on business events you can make your service operations much higher level and require fewer of them. How many business events are performed by your typical application? Three? Four? This is how many service operations you should be exposing.

相关阅读:
Top