As luck would have it, web applications are actually services under the hood so they work just fine as Windows services. The trick is how to install it as a service on Windows.
The magic command is called "sc" for service control.
Here's a quick example:
- Create a simple web project and build it as a standalone web application (I use port 8100). Note the path of the resulting executable.
- Start the Windows command line with administrator privileges.
- Enter the sc command to install the service. Do not leave out the spaces after each = in this command:
sc create RSWebSvc type= own start= auto binpath= c:\Path\To\Exe\WebApp.exe
- You should see: [SC] CreateService SUCCESS
- Now open up Control Panel and go to the Services Manager. It is located in Administrative Tools and is called Services.
- Find the service you just created, RSWebSvc. Click on it and select Start.
- Your web application is now running as a service. To test it, navigate to the URL in your browser:
- To stop the service, click on it in Service Manager and click Stop.