Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there such a thing as too many WCF services? [closed]

I have a bit of a problem, and I'm not really sure how to tackle it. I have my model assembly which contains about 200 different business objects (Order, Customer, Product, etc.).

I don't want to return an entire object graph when someone wants to get, for example, an Order. Instead I want to simply return the object and lazy-load (or even asynchronously load) the other parts. This seems like it's going to lead to a lot of "Get(Object Name)" services:

  • GetOrder(int id)
  • GetCustomer(int id)
  • GetProduct(int id)
  • etc.

I don't want to create 200 different methods, one for each Get operation. I realize I could probably do something like: GetObject(string type, int id), and then use reflection somehow to get the appropriate object back, but I think that is even worse (possibly).

If I, instead, used T4 templates to automate the job of creating each of the different services, that would be better... but it still leaves me worrying about one thing... performance.

Is it bad to have 200+ different services being exposed (one for each object)?

like image 638
michael Avatar asked Jul 05 '13 15:07

michael


People also ask

What is the need for the activation or hosting of a WCF service?

WAS Hosting − Hosting a WCF service in Windows Activation Service (WAS) is most advantageous because of its features such as process recycling, idle time management, common configuration system, and support for HTTP, TCP, etc.

What is difference between Windows service and WCF service?

A windows service is what you need. WCF is a communications library, and unless you plan to communicate with your application via a client, you don't need it. Your problem is related to activation, and keeping your code active in the background is what windows services do.

How do you consume WCF service?

With the service running, right click the project that will contain the WCF client proxy and select Add > Service Reference. In the Add Service Reference Dialog, type in the URL to the service you want to call and click the Go button. The dialog will display a list of services available at the address you specify.

Why do we need WCF service?

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.


1 Answers

From my experience, WCF + Entity Framework + Lazy loading + deep object graphs + performance requirements = big potential problems.

There is no amazing silver bullet that solves all problems, I ended up with the following:

  • lazy loading disabled. I think lazy loading just creates more problems that is solves: performance issues if not used properly, difficulty to catch exceptions (as a SQL request could be executed at any time, not just on that line of code that initially fetches the root entity from the DB)
  • T4 template modified, so the setter of navigation properties is now private. No more collection of objects automatically serialized to the client side
  • eager loaded object graphs sent to the client through WCF, as well as custom POCO (in case you want to fetch multiple entities in a single WCF call).
  • No generic repository pattern. The client just calls some GetXXXX/GetXXXByYYY methods. And even GetXXXByYYYWithZZZZWithWWWW where ZZZZ and WWWW are names of eager loaded properties. Yes, there could be lots of methods, but you build them only when actually needed by the client side of the application, and you know what you are doing. This greatly helps to have good performances.

Is it bad to have 200+ different services being exposed (one for each object)?

Those are 200+ different operations in a single service (I suppose). If your client actually needs to access to all your server-side entities, then yes, 200+ operations is OK, there is just no magic here.

like image 112
ken2k Avatar answered Oct 10 '22 03:10

ken2k