C# – Error 5 : Access Denied when starting windows service

cnetwcfwindows-services

I'm getting this error when I try to start a windows service I've created in C#:

alt text

My Code so far:

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;
}

Update #1

I solved the issue above by granting permissions to the account NETWORK SERVICE but now I have an another problem:

alt text

Update #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….

Best Answer

I realize this post is old, but there's no marked solution and I just wanted to throw in how I resolved this.

The first Error 5: Access Denied error was resolved by giving permissions to the output directory to the NETWORK SERVICE account.

The second Started and then stopped error seems to be a generic message when something faulted the service. Check the Event Viewer (specifically the 'Windows Logs > Application') for the real error message.

In my case, it was a bad service configuration setting in app.config.

Related Topic