Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Service X has zero application endpoints" unless I add an endpoint in code - why?

Tags:

c#

.net

wcf

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?

like image 497
sharptooth Avatar asked Mar 11 '11 09:03

sharptooth


1 Answers

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

The config file should contain:

<service name="MyServiceNamespace.RequestProcesssorImpl"
like image 88
Johann Blais Avatar answered Sep 19 '22 21:09

Johann Blais