title: Hosting WCF as Windows service " Service was started and Stopped"
body: <p>I am hosting WCF as Windows Service using net.tcp. After installing the windows service when I start the service, I get that service was started and stopped.</p>
  
  <p>The error says in order to In order to add an endpoint to the service 'MYService', a non-empty contract name must be specified.
     at System.ServiceModel.Description.ConfigLoader.LookupContract(String contractName, String serviceName)</p>
  
  <p>My OnStart function is as follows</p>
  
  <pre><code> protected override void OnStart(string[] args)
          {
              try
              {
                  if (myServiceHost != null)
                  {
                      myServiceHost.Close();
                  }
                  myServiceHost = new ServiceHost(typeof(MYservice));
                  myServiceHost.Open();
  
              }
              catch (Exception ex)
              {
                  log.Error("ONStart", ex);
                  throw;
              }
  
          }
  </code></pre>
  
  <p>The config file is as follows:</p>
  
  <p>
      
        
          
            
            
              
              
            
          
        
      </p>
  
  <pre><code>&lt;serviceHostingEnvironment minFreeMemoryPercentageToActivateService="10" /&gt;
  &lt;services&gt;
    &lt;service behaviorConfiguration="myServiceBehavior"
      name="myNamespace.myTestService"&gt;
      &lt;endpoint binding="netTcpBinding" bindingConfiguration="netTCPBindingConfig" contract="myNamespace.ServiceInterface.ImyTestService" /&gt;
      &lt;endpoint binding="mexTcpBinding" bindingConfiguration="" /&gt;
      &lt;host&gt;
        &lt;baseAddresses&gt;
          &lt;add baseAddress="net.tcp://10.1.3.69:8523/TestService" /&gt;
        &lt;/baseAddresses&gt;
        &lt;timeouts closeTimeout="10:00:10" openTimeout="10:01:00" /&gt;
      &lt;/host&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="myServiceBehavior"&gt;
        &lt;serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  </code></pre>
  
  <p></p>