1

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.

Prisoner ZERO
  • 13,848
  • 21
  • 92
  • 137
  • 1
    To compare Bri's and Scott's answers: which approach is sensible depends on whether the system administrator will want to stop and start the various listeners independently. If they would all be started and stopped at the same time, or if they'll be started and stopped automatically by your own software, a single service is more sensible. If the sysadmin will want to say, "stop listener E" and "start listener B" *using the Windows Services tool* then you want multiple services. – Harry Johnston Jan 16 '16 at 23:52

2 Answers2

2

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.

Community
  • 1
  • 1
bri
  • 2,932
  • 16
  • 17
  • Scott's answer implies you can only run 1...can I "register" many instances of the same EXECUTABLE on the same box? Is so, do you have a good article on that? ...thanks. – Prisoner ZERO Jan 16 '16 at 22:56
  • I basically need to run multiple instances of the same listener on one box. – Prisoner ZERO Jan 16 '16 at 22:58
  • We use an internal library to do that [see this article](http://stackoverflow.com/a/30650205/4747123) for details. Adding some detail to the answer. – bri Jan 16 '16 at 23:04
  • There are a couple answers for your install/start/stop...which one did you choose? – Prisoner ZERO Jan 19 '16 at 01:39
1

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.

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431