English 中文(简体)
Can I have multiple services hosted in a single windows executable
原标题:

My question is essentially the same as the following one but the answer did not help me.

.NET Windows Service - multiple services in one project

Essentially, I have 3 services, lets say "Service1", "Service" and "Service3".

ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
                                {
                                    new Service1("Service1"),
                                    new Service2("Service2"),
                                    new Service3("Service3")
                                };

ServiceBase.Run(ServicesToRun);

I also have installer classes with corresponding serviceInstaller.ServiceName = "ServiceX" for each of these services.

When I use installutil, i do see all 3 services on the Service manager. However, when i start them (any or all of them) only the first one ("Service1") is running.

I know this is trivial and i can probably have different installer projects for each of these but in my case, it semantically makes more sense to use just one

Your help is appreciated

Thanks Venu

最佳回答

I created a 3 service project (below) which uses a project installer for each service. I then added an installer project which installs the services into service manager. Here was my workflow:


  1. Create 3 services in a solution in Visual Studio 2008. Naming each service as Service1, Service2 and, Service3. (Being sure to change the actual service names to their respective names in the properties window.)
  2. Added an Installer project to this solution.
  3. Added the project outputs from the three service projects to the installer project.
  4. Added custom actions for all three services in the installer for Installing the services in service manager.
  5. Built and Installed.

This gives me three distinct services in service manager: Service1, Service2 and Service3

Enjoy!

http://code.google.com/p/multi-service-install/

EDIT:

I have updated the code in the repository to have one executable but two services. Each service installs to the service manager with its own name and ability to start/stop. I think this is what you re wanting, correct? Here is what I did:

  1. Created a service project.
  2. Added a second service to the same project (with a unique service name).
  3. Added an installer to both services (ServiceA and ServiceB).
  4. In the ProjectInstaller.Designer.vb file I changed the Me.Installers.AddRange line to show both of the service installers. (Me.ServiceInstaller1, Me.ServiceInstaller2)
  5. In the Main entry point of the main service (ServiceA in my case), I set the ServicesToRun variable to an array of ServiceBase containing all the services that I want it to run (ServiceA and ServiceB). This is an important step as the service manager sets a property based on the number of arguments here - either to allow multiple instances of the same exe or only a single instance.
  6. Add an installer project and use the output of Services.
  7. Add a custom action using the output from Services.

The code can still be downloaded from the same link as above.

Thanks!

问题回答

暂无回答




相关问题
windows service : configuration UI implementation options

I have a simple windows service, that might need to be configured on-the-fly (a COM port to listen to). I have done the UI as a console app that connects to the windows service through WCF, it works ...

Installing a Windows Service as a user

I m currently in the process of creating a Windows service application which will monitor changes to certain keys made in the HKEY_USERS registry. The way I do this is by collecting the SID of the ...

Writing application for both Unix and Windows

I ll write a program for Interactive UNIX (http://en.wikipedia.org/wiki/INTERACTIVE_UNIX). But in a year it will be ported to Windows. I ll write it in ANSI C and/or SH-script. When it runs on Windows ...

Windows service runs file locally but not on server

I created a simple Windows service in dot net which runs a file. When I run the service locally I see the file running in the task manager just fine. However, when I run the service on the server it ...

热门标签