在Windows Service中托管ASP.NET5 Web应用程序 [英] Hosting ASP.NET5 Web Application in Windows Service

查看:216
本文介绍了在Windows Service中托管ASP.NET5 Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于.NET Framework 4.5的现有Windows Service应用程序,并且想要添加一个用于配置和诊断的用户界面.

I have an existing Windows Service application, based on .NET Framework 4.5 and want to add an user interface for configuration and diagnostics.

在Windows Forms或WPF中,服务将通过TCP连接(.NET Remoting或WCF)将其数据发送到客户端,但是这需要在客户端或服务器端进行其他配置,并且还要求服务和客户端为具有相同的兼容性级别,在最坏的情况下,这意味着多个客户端可以提供多种服务.

In Windows Forms or WPF the service would send it's data via TCP connection (.NET Remoting or WCF) to the client, but that would require additional configuration, either on client or on server side and also requires service and client to be on the same compatibility level, which in worst case means multiple clients for multiple services.

我有一个使用新的ASP.NET5 Web应用程序在一个应用程序中融合服务和用户界面的想法.Windows服务启动时,首先,我想启动Web服务器,然后启动其余的服务.因此,用户无需安装任何其他软件即可与服务进行交互.Web应用程序和Windows服务应该在同一AppDomain中运行,以便我可以在用户界面中更改对象,并且该服务可以立即使用它.

I have an idea of melting service and user interface together in one application using new ASP.NET5 Web Application. When the Windows service starts, first I would like to start the web server and then start the rest of the service. So it would be possible for the user to interact with the service without installing any additional software. The Web Application and Windows Service should run in the same AppDomain, so that I can change an object in user interface and the service can use it immediately.

到目前为止,我已经使用新的控制台应用程序(dnx451)并通过WebHostBuilder进行托管,并获得了一个工作页面,但是我认为这不是我想要的解决方案.我得到了项目输出和一个cmd文件来启动服务器.

So far, I have played a bit with new Console Application (dnx451) and hosting via WebHostBuilder and got a working page, but I don't think that that's the solution I'm looking for. I get the project output and a cmd-file to start the server.

所以我的第一个问题是:是否有等效的WebHostBuilder for .NET 4.5来在传统的Visual Studio项目中运行网站?

So my first question is: Is there an equivalent implementation of WebHostBuilder for .NET 4.5, to run a web site in tradional Visual Studio projects?

我的第二个想法是完全在IIS中运行该服务,因此我将拥有一个托管现有服务功能的WebPage.但是我不知道IIS和Windows服务中的应用程序之间有什么区别.在这种情况下,ASP.NET 4.6又是什么呢?因为我想我必须将现有的库转换为新的ASP.NET5类库(包).

My second thought would be to completely run the service inside IIS, so I'd have a WebPage hosting the existing service functionality. But I'm not aware of any differences between applications in IIS and as Windows service. And what's about ASP.NET 4.6 in this case? Because I think I will have to convert my existing libraries into new ASP.NET5 class library (Packages).

我想到的最后一种可能性是将Web应用程序发布到IIS并作为Windows服务进行服务,并通过WCF NamedPipes进行通信,就像我对WPF或Windows Forms应用程序所做的那样.

The last possibility I could think of would be to publish web application to IIS and service as Windows service and communicate via WCF NamedPipes, like I would do with WPF or Windows Forms application.

总而言之,有什么计划要支持我的第一个想法,还是我必须选择另一个?哪个选项可能是最好的?

To sum up, Is there anything planned to support my first idea or do I have to choose one of the others? And which option would probably be the best?

推荐答案

对于.NET 4.5,您的选择是

For .NET 4.5 your options are WebAPI 2.2 or NancyFX, both running on top of Microsoft.Owin.SelfHost. Unfortunately you can't self-host MVC 5.

对于带有MVC 6的ASP.NET 5,您运气不好因为它不是一个好主意().

For ASP.NET 5 w/ MVC 6 you're out of luck since it only runs on DNX (look at the dependencies in the MVC6 nuget package, they've only got references for DNX and DNXCore), and there is no windows service bootstraper for DNX. Also, deploying .NET 4.6 to production is not a good idea (yet).

这篇关于在Windows Service中托管ASP.NET5 Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆