title: Windows service starts on Windows 7 but fails to start on Windows Server 2008 R2
body: <p>I have created a wcf service which is deployed via a managed windows service. what the onstart() does is it creates and opens a tcp host for the wcf serice.</p>
  
  <p>everything works fine in windows 7 but when I try to install the service in windows server 2008 R2 the service starts and then stops with the error that sometimes services stop when there is nothing to do. It is run under the network service account.</p>
  
  <p>I cant find anything usefull in the windows logs.</p>
  
  <p>I have tryed installing a dubug build and call debugger.launch() but its not working. I cant use remode debug because the the process does not stay open long enough for me to attach to it.
  I really dont know what to do. Here is my code:</p>
  
  <pre><code>    protected override void OnStart(string[] args)
      {
          System.Diagnostics.Debugger.Launch();
  
          try
          {
  
              //if (!System.Diagnostics.EventLog.SourceExists("i2s CU Service (eng)"))
              //{
              //    System.Diagnostics.EventLog.CreateEventSource("i2s CU Service", "Application");
              //}
              System.Diagnostics.EventLog.CreateEventSource("i2s CU Service", "Application");
          }
          catch (Exception)
          {
              //throw;
          }
          eventLog1.Source = "i2s CU Service";
          eventLog1.Log = "Application";
  
          if (serviceHost != null)
          {
              serviceHost.Close();
          }
  
          System.Configuration.AppSettingsReader reader = new System.Configuration.AppSettingsReader();
          Uri tcpUri = null;
          try
          {
              tcpUri = new Uri((string)reader.GetValue("Uri", typeof(string))); //net.tcp://localhost:8008/i2sServer
  
              serviceHost = new ServiceHost(typeof(ConcurrentUsers), tcpUri);
  
              // Create a binding that uses TCP and set the security mode to none.
              NetTcpBinding b = new NetTcpBinding();
              b.Security.Mode = SecurityMode.None;
  
              // Add an endpoint to the service.
              serviceHost.AddServiceEndpoint(typeof(IConcurrentUsers), b, "");
  
              // Open the ServiceHostBase to create listeners and start 
              // listening for messages.
              serviceHost.Open();
          }
          catch (Exception ex)
          {
              eventLog1.WriteEntry(ex.Message, EventLogEntryType.Error);
          }
  
  
          if (serviceHost.State == CommunicationState.Opened)
          {
              eventLog1.WriteEntry("Service started.", EventLogEntryType.Information);
          }
      }
  
      protected override void OnStop()
      {
          if (serviceHost != null)
          {
              serviceHost.Close();
              serviceHost = null;
          }
          eventLog1.WriteEntry("Service stopped.", EventLogEntryType.Information);
      }
  </code></pre>
  
  <p>this code as is works perfectly fine in windows 7 but I cant get it to run on win 2008 R2 server.</p>
  
  <p>Thanks in advance</p>