简体   繁体   中英

Windows Service Options

Where I used to work, we were purely Azure & at other previous jobs I did mostly web applications. In Azure, I would create a Worker to act as a Service Bus Queue Listener...but in this position, I am needing to create a Windows Service (to act as an MSMQ Listener) and it has been quite a while since I have done so & have a few minor questions.

  • QUESTION: Would a normal Windows Service do or is there a better WCF Windows Service option or equivalent?
  • QUESTION: I need to ensure multiple copies of the same service can be instantiated on the same box...how do I do this? Do I need to set any properties to do this?
  • QUESTION: If I wanted to ensure only one copy could be instantiated, how would I do that?

UPDATE:
I basically need to run many instances of the same executable on the same box. So, I am trying to figure out how to do that.

Any supporting articles are welcomed. I 'googled' quite a bit, but didn't find much that is recent. Most seem outdated. Hence, the question.

Thanks for the help.

Service doesn't mean singleton

You can register as many copies of a windows service as you'd like -- so be careful about assuming that just because it's a service it can only be run once!

If you are worried about multiple users on the same box "running" multiple copies of your exe, then running as a service solves your problem.

If you're worried that multiple copies of your service could be "installed" then you need to implement a mutex.

Think about the sqlServer exe "service." Msft creates a new service with the same exe for each sql "service" on a box.

How to Install one EXE as a service more than once.

Services are unique based on service name, not the EXE name or path. I won't go into detail on how to create a library for install/start/stop services because someone else already did.

But, I can tell you that we use this same set of methods to create multiple windows services with the same exe. The service "name" is BTMonitor, and we run several copies by just naming the service "BTMonitor$Queue1", "BTMonitor$Queue2", "BTMonitor$Queue3" etc. Note that the $ is our own convention, not some mysterious requirement.

Then, we just append command line parameters to the EXE that configure it for each "$Queue."

For the rest of your question, I'll defer to Scott's excellent answer.

Would a normal Windows Service do or is there a better WCF Windows Service option or equivalent?

It depends on what you are doing, however there is no such thing as a "WCF Windows Service", you can have a WCF Endpoint which can be hosted in a Windows service (called "Self Hosting") or you can have a WCF Endpoint hosted in IIS website using WAS to activate it on demand.

However, configuring WCF to use MSMQ is not as easy as just using HTTP (you have to configure the WAS listener for MSMQ for your IIS site) and it is recommended to put those kinds of endpoints in a windows service.

I need to ensure multiple copies of the same service can be instantiated on the same box...how do I do this? Do I need to set any properties to do this?

A windows service can not have multiple copies running, you must either write separate windows services, have one "control" service that starts up multiple WCF endpoints within a single executable, or use IIS to host multiple services at different endpoint addresses.

If I wanted to ensure only one copy could be instantiated, how would I do that?

By writing it as a windows service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM