简体   繁体   English

IIS与Windows服务?

[英]IIS vs Windows Service?

I have a C# application that needs to always be running. 我有一个需要始终运行的C#应用​​程序。 I originally planned on making this a windows service but I now have a requirement to make the application host a web admin console. 我最初计划将其作为Windows服务,但我现在需要使应用程序主机成为Web管理控制台。

I haven't played with IIS in quite a few years so my question is this: 我在几年内没有玩过IIS,所以我的问题是:

What would you recommend I use? 你会推荐我用什么?

I've thought about making a windows service and embedding a web server such as Cassini but so far I'm not very happy with the open source web servers I've looked at. 我已经考虑过制作Windows服务并嵌入像Cassini这样的Web服务器,但到目前为止我对我看过的开源Web服务器并不满意。

Can IIS handle this? IIS可以处理吗? Do people use it for this type of scenario, and if so how? 人们是否将它用于此类情景,如果是这样的话?

This sounds like a job for two separate projects. 这听起来像是两个独立项目的工作。

One is the original Windows Service. 一个是原始的Windows服务。 Windows Services are well suited for what you're doing. Windows服务非常适合您正在做的事情。

The second is the Web Project that will be used to administer the Windows Service. 第二个是用于管理Windows服务的Web项目。 This is the part that runs in IIS. 这是在IIS中运行的部分。

It depends on what you mean by always running . 这取决于你总是跑步的意思。 An ASP.NET web application deployed in IIS could very well be unloaded by the web server if there aren't any requests for certain amount of time killing all background threads. 如果没有任何请求在一定时间内终止所有后台线程,则Web服务器可以很好地卸载部署在IIS中的ASP.NET Web应用程序。 So if you want an ever running background thread it would be better suited to use a Windows Service. 因此,如果您想要一个永远运行的后台线程,那么它将更适合使用Windows服务。 As far as the web admin is concerned, well, here you don't have much choice: ASP.NET in IIS. 就Web管理员而言,在这里你没有太多选择:IIS中的ASP.NET。 In order to do something useful those two applications should be able to find a common language to talk. 为了做一些有用的事情,这两个应用程序应该能够找到一个可以交谈的通用语言。 So you could use a database to store the results into which could be used by both applications. 因此,您可以使用数据库来存储两个应用程序可以使用的结果。

IIS will run your app on first request, not on server boot. IIS将在第一次请求时运行您的应用程序,而不是在服务器启动时 So you will still need to run a service to ensure your app is always running. 因此,您仍需要运行服务以确保您的应用始终在运行。

You can use IIS as a webserver for your web admin part, and link your ASP.net app with your service by means of a configuration database (easy) or webservices (a little more tricky). 您可以将IIS用作Web管理部件的Web服务器,并通过配置数据库(简单)或Web服务(稍微复杂一点)将ASP.net应用程序与您的服务链接。

Windows and Web services are two very different creatures. Windows和Web服务是两种截然不同的生物。 A web service will expose external methods that you can implement against an application, while a windows service is an entity within itself. Web服务将公开可以针对应用程序实现的外部方法,而Windows服务本身就是一个实体。 If you're planning on using this service on a timed interval to perform an operation, a Windows service would be the right way to go. 如果您计划在定时间隔内使用此服务来执行操作,则Windows服务将是正确的方法。 If you use a web service, you will need to invoke the method you wish to run from a secondary application. 如果使用Web服务,则需要调用要从辅助应用程序运行的方法。

If you need to queue commands against your windows service, you could always create a database that was accessible by both your website and your windows service. 如果您需要针对Windows服务排队命令,您可以随时创建一个可供您的网站和Windows服务访问的数据库。 This way you could send commands and query data between the two. 这样您就可以在两者之间发送命令和查询数据。 Placing a web service in to serve as an intermidary between the two may be overkill. 将Web服务置于两者之间作为中间人可能是过度的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM