Search code examples
c#.netwcfweb-servicesself-hosting

Starting self hosted WCF services on demand


Is it possible to start self hosted WCF services on demand?

I see two options to accomplish this:

  • Insert a listener in the self hosted WCF's web server and spin up a service host when a request for a specific service comes in, before WCF starts looking for the existence of that endpoint; or

  • Integrate a web service in process, start a service host for a request if it isn't running yet and redirect the request to that service host (like I suspect IIS does).

I cannot use IIS or WAS because the web services need to run in process with the UI business logic.

Which is feasible and how can I accomplish this?

EDIT:
I cannot just start the service hosts because there are hundreds, most (about 95%) of which are (almost) never used but need to be available. This is for exposing a business logic layer of 900 entities.


Solution

  • Went the following route:

    • Create a single service host;

    • Create a dynamic proxy which implements all service interfaces;

    • Add a service endpoint for every interface the dynamic proxy implements;

    • Dispatch to the correct implementation from the dynamic proxy.