2012-03-07 231 views
1

我創建了一個通過託管Windows服務部署的wcf服務。 onstart()所做的是創建併爲wcf serice打開一個tcp主機。Windows服務在Windows 7上啓動,但無法在Windows Server 2008 R2上啓動

在Windows 7中一切正常,但當我嘗試在Windows Server 2008 R2中安裝服務時,服務啓動,然後停止,有時服務停止,當沒有任何事情時會停止。它在網絡服務帳戶下運行。

我無法找到任何有用的Windows日誌。

我嘗試安裝dubug構建並調用debugger.launch(),但它不工作。我不能使用remode調試,因爲這個過程沒有保持足夠長的時間來打開它。 我真的不知道該怎麼辦。這是我的代碼:

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); 
    } 

此代碼是在Windows 7中工作完美,但我不能讓它在win 2008 R2服務器上運行。

在此先感謝

+1

你不處理的第一個例外相同的用戶帳戶下運行控制檯的副本,這個問題可能發生在那裏。 – vulkanino 2012-03-07 16:04:18

+0

我已經嘗試刪除整個錯誤日誌的東西,仍然是相同的 – Ares 2012-03-07 16:59:48

+0

這似乎並沒有在Windows 7中的問題,並在之前所述的調試器不會啓動! – Ares 2012-03-07 17:09:00

回答

0

重構您的應用程序作爲控制檯應用程序,然後在需要的環境中運行,它能夠輕鬆地調試。

我敢肯定,這個問題就會發現自己,一旦你分配給你的windows服務

+0

所以你不認爲有一個problrm與服務,但與內容。 ok會這樣做 – Ares 2012-03-07 20:14:40

+0

當你完成時分享結果 – CSharpenter 2012-03-07 20:17:06

+0

有關你的錯誤的任何消息?您是否創建了Console Replica? – CSharpenter 2012-03-08 12:57:51

相關問題