Question

I need to create many windows services to host many WCF Service so I can stop a single one (for example to update it) and keep the other running.

Since I don't want to create a windows service for every WCF Service I have, I'm trying to create a C# application that can register itself as a windows service but with different parameters (and service name of course).

For example calling it this way:

MyService.exe /install WcfService1.dll
MyService.exe /install WcfService2.dll

This creates two different windows service like these:

WcfService1 -> MyService.exe /run WcfService1.dll
WcfService2 -> MyService.exe /run WcfService2.dll

I can't find a way to do this other than editing directly the registry.

Was it helpful?

Solution

I've found a nicer way to do it: sc.exe

sc.exe create WcfService1 binPath= "MyService.exe /run WcfService1.dll"

so I just need to create a bat/cmd to launch this command.

OTHER TIPS

By its nature, a service is designed to be the go-to process for dealing with a particular thing, and having multiple instances is generally not a good idea. However, it is possible to do what you want; for instance, you can have multiple instances of SQL Server running at one time.

Have a read of this. Basically, your service installer can be given some command-line or other configurable argument that will tell it the name to which it should register itself in Windows as a service. This is normally automatic based on the service installer's and service executable's properties, but all of this can be set dynamically as well. Change the name, and you change the service registration. The name of the service should be (AFAIK) inspectable by the executable being run as the service, which can tell it the WCF service for which it is responsible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top