I have to write an windows service in .NET 4.6/C#, which reads messages from RabbitMQ queues and does some processing based on message type. Processing includes reading the message and based on business rules, insert/update SQL database and send out another message confirming the successful processing of the message received.

Entire service is done implementing OnSatrt() and OnStop() events in ServiceBase class. Reading queues and processing is all completed. The missing piece for me here is how to have the same windows service to accept http commands for starting, stopping and restarting the service. How can I design a windows service with http capabilities and 24x7 processing logic within it?

I am not looking for a whole design or entire code here, just need an idea on how a windows service in .NET can accept http commands while its processing data from queues.


1 Answer 1


Although it is certainly possible for a Windows service to listen for http requests (that's what IIS does after all), you cannot have a Windows service listen for commands to start and stop itself. That would be a paradox. How can your service listen for a start command before it is started?

The key is to have a second service control the first one. Write a small web service to accept the start/stop/restart commands, host it in IIS, and pass the commands down to the Windows service control manager. You can use any convenient technology for this, ASP.NET Web API or WCF will do fine.

  • Make sense :) I did not think about the paradox. Will go the web api route. Thanks.
    – PushCode
    Commented Jul 18, 2017 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.