c# - 错误 5 : Access Denied when starting windows service

标签 c# .net wcf windows-services

当我尝试启动我在 C# 中创建的 Windows 服务时出现此错误:

alt text

到目前为止我的代码:

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 授予权限解决了上述问题,但现在我遇到了另一个问题:

alt text

更新#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/

相关文章:

c# - JsonArray.Parse(...) 错误

c# - MVVM 模式、IDataErrorInfo 和绑定(bind)显示错误?

wcf - 如何使用 Json.Net 从 WCF Rest 服务 (.NET 4) 返回 json,而不是用引号引起来的字符串?

c# - Azure Web 应用程序。免费比基本版和标准版更快?

.net - 选项卡页在 C# (winform) 中添加一个新属性

WCF:路由服务和 "Unable to automatically debug ' 服务名称'。无法调试远程过程

c# - 为什么 RedirectToAction 不重定向?

c# - 如何杀死一个C#进程?

c# - 有没有办法在 where 子句中访问私有(private)属性(property)?

c# - 使用 ExpertPDF 从 HTML 生成的 PDF 的质量差异