c# – 错误5:启动Windows Service时访问被拒绝
问题:
当我尝试启动在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
服务无法启动。 System.InvalidOperationException:服务’RightAccessManagementWcf.RightAccessWcf’具有零个应用程序端点(非基础结构)。 这可能是因为没有为您的应用程序找到配置文件,或者是因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在服务元素中未定义端点。 在System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescription描述)在System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription描述,ServiceHostBase serviceHost)在System.ServiceModel.ServiceHostBase.InitializeRuntime()在System.ServiceModel.ServiceHostBase.OnOpen()在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)在C:\\ Users中的RightAccessHosting.RightAccessHost.OnStart(String [] args)处。
I’m getting this error when I try to start a windows service I’ve created in C#:My Code so far:Update #1I solved the issue above by granting permissions to the account NETWORK SERVICE but now I have an another problem:Update #2Service 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….