Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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(Here is my code):
C#
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
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>
Posted
Updated 25-Dec-17 20:15pm
v6
Comments
member 8888995 11-Dec-13 0:11am    
will you please check your start method outside windows service application with a breakpoint.
TryAndSucceed 12-Dec-13 16:02pm    
As the error itself mentions, you do not have endpoints in your config file. You need to define the endpoints pointing towards this service, installed may be locally or anywhere.

1 solution

Please check you app config file, should be as below


<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"
 name="WcfServiceLibrary1.Service1">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
          contract="WcfServiceLibrary1.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8733/Service1" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfServiceLibrary1.Service1Behavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900