title: "Service X has zero application endpoints" unless I add an endpoint in code - why?
body: <p>I followed <a href="http://msdn.microsoft.com/en-us/library/ms733069.aspx" rel="nofollow noreferrer">this MSDN article</a> to create a WCF service hosted in a managed NT service thoroughly.</p>
  
  <p>When I click "Start" in services console I then see the following in Event Viewer:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>I tried to check all possible reasons I could find. Here's the service description in App.Config file:</p>
  
  <pre><code> &lt;service name="MyServiceNamespace.RequestProcessorWindowsService"
             behaviorConfiguration="RequestProcessorServiceBehavior"&gt;
      &lt;host&gt;
        &lt;baseAddresses&gt;
          &lt;add baseAddress="http://localhost:8095/RequestProcessorService"/&gt;
        &lt;/baseAddresses&gt;
      &lt;/host&gt;
      &lt;endpoint address= ""
                binding="wsHttpBinding"
                contract="MyServiceNamespace.IRequestProcessor" /&gt;
      &lt;endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" /&gt;
    &lt;/service&gt;
  </code></pre>
  
  <p>All entities are <a href="https://stackoverflow.com/questions/2328840/service-has-zero-application-non-infrastructure-endpoints/3305260#3305260">named with their namespaces</a>, so that's not the problem. The App.Config file is placed into bin\Debug - exactly where the NT service starts from.</p>
  
  <p>But when I change my <code>ServiceBase</code> descendant <code>OnStart()</code> from the original implementation:</p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p>to the following one so that it calls <code>AddServiceEndpoint()</code> the service starts okay (but I can't add the reference to it, so I guess something else goes wrong):</p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p>Why doesn't my service start when configured through App.Config?</p>