当我尝试启动我在 C# 中创建的 Windows 服务时出现此错误:
到目前为止我的代码:
private ServiceHost host = null;
public RightAccessHost()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
host = new ServiceHost(typeof(RightAccessWcf));
host.Open();
}
protected override void OnStop()
{
if (host != null)
host.Close();
host = null;
}
更新#1
我通过向帐户NETWORK SERVICE 授予权限解决了上述问题,但现在我遇到了另一个问题:
更新#2
Service cannot be started. System.InvalidOperationException: Service 'RightAccessManagementWcf.RightAccessWcf' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element. at System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescription description) at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) at System.ServiceModel.ServiceHostBase.InitializeRuntime() at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at RightAccessHosting.RightAccessHost.OnStart(String[] args) in C:\Users....
最佳答案
我意识到这篇文章已经过时了,但没有明确的解决方案,我只想说说我是如何解决这个问题的。
第一个 Error 5: Access Denied
错误已通过将输出目录的权限授予 NETWORK SERVICE
帐户来解决。
第二个 Started and then stopped
错误似乎是服务出现故障时的一般消息。检查事件查看器(特别是“Windows 日志 > 应用程序”)以获取真正的错误消息。
就我而言,这是 app.config 中错误的服务配置设置。
关于c# - 错误 5 : Access Denied when starting windows service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4267051/