2

After building installing windows service I got first error "windows could not start service on local computer error 5 access is denied" when I try to start a windows service. I resolved first error by following these steps of solution : Cannot Start Windows Service in NetworkService account .After this the notification of first error Vanished but another notification for error appeared "This service on local computer started and then stopped. some services stop automatically if then are not in use by other servces or programs". How i can solve this issue?

Note : I have visited many posted answer but they didn't solved problem .

Windows service on Local Computer started and then stopped error

Windows Event Viewer notification :

Service cannot be started. System.InvalidOperationException: Service 'CustomerServiceLibrary.CustomersService'  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.EnsureThereAreApplicationEndpoints(ServiceDescription description)
   at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
   at System.ServiceModel.ServiceHostBase.InitializeRuntime()
   at System.ServiceModel.ServiceHostBase.OnBeginOpen()
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at WindowsServiceHost.WCFService.OnStart(String[] a...

The Service on local computer started and then stopped ,Some services stop automatically if there are not in use by other services or programs

Edited:

namespace WindowsServiceHost
{
    public partial class WCFService : ServiceBase
    {
        public WCFService()
        {
            InitializeComponent();
        }

        private ServiceHost host = null;
        protected override void OnStart(string[] args)
        {
            System.Diagnostics.Debugger.Launch();
            host = new ServiceHost(typeof(CustomersService));
            host.Open();
        }

        protected override void OnStop()
        {
            if (host != null)
            {
                host.Close();
            }
            host = null;
        }
    }
}

app .config file :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>
Community
  • 1
  • 1
user3056831
  • 163
  • 2
  • 2
  • 8
  • 2
    Can you post your code for the service? It's possible that an exception is being thrown somewhere in your code. Have you tried debugging it? – Arian Motamedi Dec 10 '13 at 06:15
  • i am following video tutorials on "AppDev WCF_Using_C#_2008" .They just build it before installing and starting .. – user3056831 Dec 10 '13 at 06:20
  • 1
    The trace error log is very obvious: there are no endpoints defined for the service host. Can you post the `app.config` file (or is the endpoint being generated in code?) – Arian Motamedi Dec 10 '13 at 16:18

4 Answers4

1

Like PoweredByOrange alreadys said, in your app.config is almost no configuration and also no endpoint defined. You should have a system.servicemodel element in your app.config that defines your service including which contract, endpoint, binding, etc

Here you can see a Simple configuration on MSDN

Community
  • 1
  • 1
Martin
  • 25
  • 5
0

You can actually check the event handler. It will intimate you the mistake you have done in the configuration file. Some syntax error in the configuration file will be the reason for this kind of message box.

Priya
  • 1,879
  • 2
  • 11
  • 6
0

I had the same problem and in my case was when I tried to open the host in the OnStart method.

The problems was for configuration of the service. How it is hard to debug a windows service, I use a try/catch block and in the catch, I wrote the message on a text file as log. You can have more details about the real error.

Another option is to create a console application to host the service and debug in this console aplication, it is easier to debug the service in a console application.

Álvaro García
  • 18,114
  • 30
  • 102
  • 193
-1

Try changing config name from app.config to web.config.

http://social.msdn.microsoft.com/Forums/vstudio/en-US/b224217f-f198-4179-8a88-4e019e420ea1/service-xxx-has-zero-application-noninfrastructure-endpoints?forum=wcf

  • 2
    OP is hosting the service in a **Windows Service** - they don't have (and couldn't use) a Web.config. – Tim Dec 10 '13 at 16:14