简体   繁体   English

将自托管SignalR Windows服务部署/安装到Windows Server 2012

[英]Deploying/Installing Self Hosted SignalR Windows Service to Windows Server 2012

I'm at the final stages of building a framework for a custom CMS which leverage's SignalR to do some magic. 我处于为自定义CMS构建框架的最后阶段,该框架利用SignalR进行一些处理。

I have this running perfect in a console application but it's less than desirable in a production environment. 我在控制台应用程序中具有完美的运行效果,但在生产环境中却不尽人意。 So I've decided to port the code over to a Windows Service which was not particularly difficult but in all reality there's scattered information on deploying and installing. 因此,我决定将代码移植到Windows Service上,这并不是特别困难,但实际上在部署和安装方面存在分散的信息。

There seems to be multiple SO posts and numerous developer articles but they never seem to cover the whole topic. 似乎有很多SO帖子和许多开发人员文章,但它们似乎从来没有涵盖整个主题。 As Windows Service's are very much alien to me, I was hoping someone could break down how this is done. 由于Windows Service对我来说非常陌生,所以我希望有人可以分解它的完成方式。 Hopefully should provide a great resource for others. 希望应该为他人提供大量资源。

So key questions: 所以关键问题:

  1. What is the best directory for a window service to live? 启用窗口服务的最佳目录是什么?
  2. How do you install? 如何安装? (Double click the exe)? (双击exe)?
  3. How do you run the service once installed? 安装后如何运行该服务?
  4. Will SignalR permanently run in the background? SignalR是否将在后台永久运行?

For the sanity of the post I'll add some code: 为了使文章更加合理,我将添加一些代码:

   public partial class SignalRService : ServiceBase
    {
        IDisposable SignalR;
        public SignalRService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            string url = "http://localhost:8080";
            SignalR = WebApp.Start(url); 
        }

        protected override void OnStop()
        {
            SignalR.Dispose();
        }
    }

 //Main that starts the service
 static void Main()
   {
      ServiceBase[] ServicesToRun;
      ServicesToRun = new ServiceBase[] 
       { 
         new SignalRService() 
       };
     ServiceBase.Run(ServicesToRun);
    }

I would be extremely grateful, if anyone could clarify these key points and centralize a resource for other's to view. 如果有人能阐明这些要点并集中资源供他人查看,我将非常感激。

Regards, 问候,

I don't think there is any kind of constraint about where to deploy your service, any directory will do. 我认为对于将服务部署到何处没有任何限制,任何目录都可以。 As for the rest, you can install it like this: 至于其余的,您可以这样安装:

installutil.exe SignalRService.exe

and to start it you can use either the Services panel under the Administrative Tools , or the command line ( net start/net stop commands, see here ) 要启动它,可以使用“ 管理工具”下的“ 服务”面板,也可以使用命令行( net start/net stop命令,请参见此处

SignalR will be alive as long as the service will (with proper error handling, of course). 只要该服务有效,SignalR就会一直存在(当然,通过适当的错误处理)。

You can get much more detail about all these things here (for example about where you can find installutil.exe ). 您可以在此处获得有关所有这些内容的更多详细信息(例如,有关在何处可以找到installutil.exe )。

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

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