11

I followed this MSDN article to create a WCF service hosted in a managed NT service thoroughly.

When I click "Start" in services console I then see the following in Event Viewer:

Service cannot be started. System.InvalidOperationException: Service 'MyServiceNamespace.RequestProcessorImpl' 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.

I tried to check all possible reasons I could find. Here's the service description in App.Config file:

 <service name="MyServiceNamespace.RequestProcessorWindowsService"
           behaviorConfiguration="RequestProcessorServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8095/RequestProcessorService"/>
      </baseAddresses>
    </host>
    <endpoint address= ""
              binding="wsHttpBinding"
              contract="MyServiceNamespace.IRequestProcessor" />
    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
  </service>

All entities are named with their namespaces, so that's not the problem. The App.Config file is placed into bin\Debug - exactly where the NT service starts from.

But when I change my ServiceBase descendant OnStart() from the original implementation:

public class RequestProcessorWindowsService : ServiceBase {
    public ServiceHost serviceHost = null;
    //other methods skipped 
    protected override void OnStart(string[] args)
    {
        if( serviceHost != null ) {
       serviceHost.Close();
        }
        serviceHost = new ServiceHost( typeof(RequestProcesssorImpl) );
        serviceHost.Open();
    }
}

to the following one so that it calls AddServiceEndpoint() the service starts okay (but I can't add the reference to it, so I guess something else goes wrong):

public class RequestProcessorWindowsService : ServiceBase {
    public ServiceHost serviceHost = null;
    //other methods skipped 
    protected override void OnStart(string[] args)
    {
        if( serviceHost != null ) {
       serviceHost.Close();
        }
        Uri baseAddress = new Uri("http://localhost:8095/RequestProcessorService");
        serviceHost = new ServiceHost( typeof(RequestProcesssorImpl), baseAddress );
        serviceHost.AddServiceEndpoint( typeof(IRequestProcessor), new BasicHttpBinding(), baseAddress );
        serviceHost.Open();
    }
}

Why doesn't my service start when configured through App.Config?

Community
  • 1
  • 1
sharptooth
  • 167,383
  • 100
  • 513
  • 979

1 Answers1

14

The service name in the configuration file does not match the service implementation class.

The config file should contain:

<service name="MyServiceNamespace.RequestProcesssorImpl"
Johann Blais
  • 9,389
  • 6
  • 45
  • 65
  • Okay, I tried it and it completely solved my problem and I can even add a reference to my WCF service from another project. Thank you very much. – sharptooth Mar 11 '11 at 10:20
  • Always put the class implementing the service contract. It is the only one that matters from the WCF host perspective. – Johann Blais Mar 11 '11 at 10:27
  • thanks , your the first one to actually just say what is needed to be done :). http://stackoverflow.com/questions/9814281/service-has-zero-application-non-infrastructure-endpoints – eran otzap Mar 21 '12 at 23:35