-
Notifications
You must be signed in to change notification settings - Fork 25.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Article to Show How to Run a DNX Application as a Windows Service #390
Comments
Here is a follow up articles that builds on the one above and shows how to host ASP.NET 5 with static files and MVC 6 in a Windows service: http://taskmatics.com/blog/host-asp-net-in-a-windows-service/ |
Sounds good. We would also welcome a PR on this one. |
Another vote for this. We have a product that runs on premise for each customer. It uses Windows Services hosting WCF with WPF clients. We want to add web UI's to our product using skill sets we are familiar with (.NET) but don't want to have to deploy IIS across our customer base to do it - that would be 000's of instances of IIS we have to worry about! ASP.NET hosted in a windows service would be perfect for us, but I am unsure whether this is an expected/supported deployment scenario for ASP.NET 5?? easyt has done some great work with his articles, but it still seems a bit hacky having to create a dnx console app and then add in ASP.NET manually - I would like to create a normal asp.net 5 project (so I can use all the tools available in VS to help me) and then run that as a windows service. I am trying to do this currently but it would be great to get an article from the experts! thanks |
As I said above: "I would like to create a normal asp.net 5 project (so I can use all the tools available in VS to help me) and then run that as a windows service" Well, its seems I can. You can just add a Program.cs class to your asp.net project something like this: using System; public class Program : ServiceBase
} And set up a new command in project.json: "commands": { Note that this also works with the WebListener Service. If you publish the project to the file system you can then run it as a windows service by referencing "service.cmd" as described by easyt in this article http://taskmatics.com/blog/host-asp-net-in-a-windows-service/. Pretty simple and it works. During development you just work as if its a normal asp.net project, using IIS Express or console to host it. I've no idea if this is a good/robust way to do it though. e.g. there is hardly a graceful shutdown when you stop the service! |
Bill, Pull the code from this repo: https://github.com/taskmatics/aspnet-windows-service. It runs in VS by default using the command line. If you want to run it as a service, you can use install.cmd and attach VS to the running dnx.exe process. There is an uninstall.cmd that will remove the service as well, and you can tweak those scripts as necessary. It also has a graceful shutdown of the web server. |
Hi Erez, Thanks for getting in touch. I saw this very helpful example. In fact I may have given up without it! We may use this approach if it is the recommended way to host in a service. However, if it is possible, being able to just add a single class containing very little code to a standard ASP.NET project would be much better for us. I want to keep things as “normal” as possible so devs can learn from examples based on the standard project template and use all that comes with it (grunt, bower etc.). I realise you could probably set all this up in the console app project as well but it’s a lot of extra work and requires a lot more knowledge. The code I posted achieves the simplicity I am after, I’m just not sure how robust it is! I would be more comfortable if I was able to shutdown gracefully like in your example, but I haven’t found a way to do that yet. Maybe I could use a program.cs like yours inside the asp.net project to get more control over the shutdown… Bill Bill, Pull the code from this repo: https://github.com/taskmatics/aspnet-windows-service. It runs in VS by default using the command line. If you want to run it as a service, you can use install.cmd and attach VS to the running dnx.exe process. There is an uninstall.cmd that will remove the service as well, and you can tweak those scripts as necessary. It also has a graceful shutdown of the web server. — |
Note that neither approach shown above will work in RC1 due to changes in the entrypoint semantics and how servers are started. see here At first glance the changes look like it will be easier to run a dnx application up as a service, and I can get an asp.net MVC application to run as a service easily enough. Unfortunately it won't serve any pages at the moment! I will post here if I work out a complete solution... |
The code in taskmatics/aspnet-windows-service has been updated to work on RC1. What issues are you seeing, exactly? |
I have also provided a pull request to the aspnet/Hosting repo with a new project that will allow users to host ASP.NET in a Windows service with zero code: The code example that uses this can be found at this branch: The install.cmd has been updated to use the 'svc' command which uses the new project I submitted (Microsoft.AspNet.Hosting.WindowsService) as the entry point. |
Your new code works with RC1. Sorry I missed that update. I checked your blog for updates, but not your repo. (I now realise I should have been watching it, but I am a Git Newbie!). I still have a problem as I can't get it to run with WebListener (which I need for windows authentication - at least I think I do). That is not to do with your implementation I don't think, WebListener doesn't seem to work at all in RC1 - at least not for me! see here The pull request looks great. It's exactly the way I would like it to work. |
@danroth27, I have a pull request (aspnet/Hosting#494) that makes it much more simple to host ASP.NET in a Windows service. I'd be glad to write this doc. I read CONTRIBUTING.md, forked the repo with a new branch and got sphinx-autobuild set up. A couple questions:
Thanks. |
@easyt Are you still interested in writing this doc? We would need it to be based on our RC2 bits. I would put it under Publishing and Deployment |
Yes. Of course. I'd be glad to write it up. Do you have any guidelines to follow, or should I just go by the feel of the other articles on docs.asp.net? |
See https://docs.asp.net/en/latest/contribute/index.html for our existing guidelines. I recommend starting with an outline and posting it here so that we can give feedback before you write a bunch of content. |
We now have a package available for this specific scenario: https://www.nuget.org/packages/Microsoft.AspNetCore.Hosting.WindowsServices/ |
This looks to be superseded by #2467 |
Damian Edwards told us, on the ASP.NET Community Standup this week, to post this issue. There should be an article describing how to run a DNX application (and subsequently ASP.NET 5) as a Windows service.
This is a use case for headless Windows services that need to expose an admin UI and choose to so though a web interface. We currently run our admin site for within our Windows service through a mini web server we developed.
Now, that ASP.NET can be hosted in a console application, it makes sense for us to move to that.
Currently there is no documentation about this scenario, so we came up with our own. You can base the official article on our write up: http://taskmatics.com/blog/run-dnx-applications-windows-service/
The article describes how to run a DNX app in a Windows service. We will have another follow up article explaining how to bootstrap ASP.NET 5 and MVC from within the service.
Thanks.
The text was updated successfully, but these errors were encountered: