异步套接字服务器无法启动Windows服务 [英] Asynchronous Socket Server failed to start with Windows Service

查看:71
本文介绍了异步套接字服务器无法启动Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过引用https://gist.github.com/leandrosilva/656054创建了异步套接字服务器程序,它正在使用控制台程序,但在作为Windows服务运行时失败。低于例外。我无法追踪错误的
。任何人请帮帮我。

i have created asynchronous socket server program by refering from https://gist.github.com/leandrosilva/656054, it is working with console program, but failing when running as windows service. Getting below exception. I could not able to trace what went wrong. Any one please help me.

推荐答案

在您的Program.Main中,您正在创建MIPService的实例。那就是触发对MIPService的静态构造函数的调用。该方法引用了一个null对象并崩溃。由于我们无法访问您的代码,您必须自己调试它。

In your Program.Main you are creating an instance of MIPService. That is triggering a call to the static constructor for MIPService. That method is referencing a null object and crashing. Since we don't have access to your code you'll have to debug it yourself.

如果没有更多信息,我将打赌MIPService正在尝试进行网络调用您没有在具有网络访问权限的帐户下运行该服务。要访问网络,您需要以NETWORK SERVICE或具有网络访问权限的用户
帐户运行服务。 SYSTEM和LOCAL SERVICE没有此访问权限。

Without any more information I'm going to wager that MIPService is trying to make a network call and you are not running the service under an account with network access. To access the network you need to run the service either as NETWORK SERVICE or a user account with network access. SYSTEM and LOCAL SERVICE do not have this access.

我看到的另一个问题是,这是在Program.Main中发生的。那是错的。 Program.Main将在服务进程启动时调用,而不是在服务启动时调用。除了实例化服务类的实例
之外,你不应该在Program.Main中做任何事情。您的服务类也不应在其构造函数中执行任何操作。应该在服务的OnStart方法中完成服务的任何初始化(包括依赖项)。当服务是
启动时,这是唯一被调用的方法。如果用户停止服务并重新启动它,则再次调用OnStart。最初创建的服务实例在服务进程执行之前永远不会消失,因此不应该挂起任何资源(因为服务
甚至可能不运行)。

Another issue I see is that this is occurring in Program.Main. That is wrong. Program.Main is going to be called when the service process is started, not when your service is started. You should do nothing in Program.Main other than instantiate an instance of your service class. Your service class should do nothing in its constructor either. Any initialization (including dependencies) that a service has should be done in the service's OnStart method. This is the only method that gets called when a service is started. If the user stops your service and restarts it then OnStart is called again. The instance of your service that was initially created never goes away until the service process does and therefore should not hang onto any resources (since the service may not even be running).


这篇关于异步套接字服务器无法启动Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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