Luke Machowski
Luke Machowski

Reputation: 4211

How do I start an out of process instance of a WCF service?

I would like to start a new instance of a wcf service host from another (UI) application. I need the service to be out of process because I want to make use of the entire 1.4GB memory limit for a 32bit .NET process.

The obvious method is to use System.Diagnostics.Process.Start(processStartInfo) but I would like to find out whether it is a good way or not. I am planning on bundling the service host exe with the UI application. When I start the process, I will pass in key parameters for the WCF service (like ports and addresses etc). The UI application (or other applications) will then connect to this new process to interact with the service. Once the service has no activity for a while, it will shut itself down or the UI can explicitly make a call to shut the service down.

Upvotes: 2

Views: 1272

Answers (2)

Matt Davis
Matt Davis

Reputation: 46052

Perhaps I'm completely offbase here, but I don't think there is a 1.4 GB memory limit for .NET processes. The memory allocated for each process is managed by the OS. For 32-bit opeating systems, there is a 4 GB memory space available, but that is shared among all of the processes. So while it may appear that there is only 1.4 GB available, it's not technically true.

The only reason I bring that up is to say that the other way to approach this would be to load your WCF service inside a separate AppDomain within your UI application. The System.AppDomain class can be thought of as a lightweight process within a process. AppDomains can also be unloaded when you are finished with them. And since WCF can cross AppDomain boundaries as well as process boundaries, it's simply another consideration.

If you are not familiar with AppDomains, the approach that @marc_s recommended is the most straightforward. However, if you are looking for an excuse to learn about AppDomains, this would be a great opportunity to do so.

Upvotes: 0

marc_s
marc_s

Reputation: 755381

You can definitely do this:

  • create a console app which hosts your ServiceHost
  • make that console app aware of a bunch of command line parameters (or configure them in the console app's app.config)
  • launch the console app using Process.Start() from your UI app

That should be fairly easy to do, I'd say.

Upvotes: 3

Related Questions