本文介绍了使用Topshelf创建的Windows服务会自动停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Topshelf创建了Windows服务. 在Start()中,我配置了在控制台应用程序中创建的SelfHosted WebAPI,如下所示

:

公共无效Start()
        {
            尝试
            {
                baseUri ="http://localhost:8080&";

                Console.WriteLine(正在启动Web服务器...");

                var config = new HttpSelfHostConfiguration(baseUri);
                config.MapHttpAttributeRoutes();
                config.Routes.MapHttpRoute(
                "DefaultApi",
                " api/{controller}/{id}",
                新的{id = RouteParameter.Optional});

                使用(HttpSelfHostServer服务器=新的HttpSelfHostServer(config))
                {
                    Console.WriteLine(服务器在{0}运行-",baseUri);

                    server.OpenAsync().Wait();
                    Console.WriteLine(按Enter退出.");
                    Console.ReadLine();
                }

                Console.WriteLine(按Enter退出.");
                Console.ReadLine();
            } 

我在ConfigureService类中将其配置为

尝试
            {
                HostFactory.Run(configure =>
                {
                    configure.Service< WebServer>(service =>
                    {
                        service.ConstructUsing(s => new WebServer());
                        service.WhenStarted(s => s.Start());
                        service.WhenStopped(s => s.Stop());
                    });

                    //窗口服务用来运行Process Engine的设置帐户.
                    configure.RunAsLocalService();
                    configure.StartAutomatically();
                    configure.SetServiceName("Engine");
                    configure.SetDisplayName("Engine");
                    configure.SetDescription(引擎Windows服务");
                });
            } 

最后是我在控制台应用程序的main()中调用

 ConfigureService.Configure();

                Console.ReadLine(); 

现在,当我调试此应用程序时,一切正常.服务启动,我可以点击指定的URL.但是,当我使用命令行安装此服务时,该服务会启动,但是当我向url发送请求时,该服务会自动停止.

我在事件日志中发现了以下错误消息

引擎服务终止,并出现以下错误:
没有足够的存储空间来处理此命令.

我找到了一些在线解决方案,并将IRPStackSize的大小增加到最大(十进制为80),但对我不起作用.请帮忙.

解决方案


I have created a Windows Service using Topshelf. In the Start() I have configured a SelfHosted WebAPI created in a Console application as follows 

public void Start()
        {
            try
            {
                baseUri = "http://localhost:8080";

                Console.WriteLine("Starting web Server...");

                var config = new HttpSelfHostConfiguration(baseUri);
                	config.MapHttpAttributeRoutes();
                	config.Routes.MapHttpRoute(
                	    "DefaultApi",
                	    "api/{controller}/{id}",
                	    new { id = RouteParameter.Optional });

                using (HttpSelfHostServer server = new HttpSelfHostServer(config))
                {
                    Console.WriteLine("Server running at {0} - ", baseUri);

                    server.OpenAsync().Wait();
                    Console.WriteLine("Press Enter to quit.");
                    Console.ReadLine();
                }

                Console.WriteLine("Press Enter to quit.");
                Console.ReadLine();
            }

I configured this in my ConfigureService class as 

            try
            {
                HostFactory.Run(configure =>
                {
                    configure.Service<WebServer>(service =>
                    {
                        service.ConstructUsing(s => new WebServer());
                        service.WhenStarted(s => s.Start());
                        service.WhenStopped(s => s.Stop());
                    });

                    //Setup Account that window service use to run Process Engine.
                    configure.RunAsLocalService();
                    configure.StartAutomatically();
                    configure.SetServiceName("Engine");
                    configure.SetDisplayName("Engine");
                    configure.SetDescription("Engine Windows Service");
                });
            }

and finally in the main() of the console application I am calling 

                ConfigureService.Configure();

                Console.ReadLine();

Now when I debug this application everything works fine. The service starts and the I can hit the url specified. But when I install this service using command line, the service starts but when I send a request to the url the service stops automatically. 

I found the following error message in the event logs 

The Engine service terminated with the following error: 
Not enough storage is available to process this command.

I found some online solutions for this and increased the size of IRPStackSize to it's maximum that is 80 in decimal but didn't work for me. Please help. 

解决方案


这篇关于使用Topshelf创建的Windows服务会自动停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:46