![](/img/trans.png)
[英]Application built on Windows Server 2012 R2 fails on windows server 2008 R2
[英]Windows service starts on Windows 7 but fails to start on Windows Server 2008 R2
我創建了一個wcf服務,該服務是通過托管Windows服務部署的。 onstart()的作用是創建並打開wcf服務的tcp主機。
在Windows 7中一切正常,但是當我嘗試在Windows Server 2008 R2中安裝該服務時,該服務啟動,然后停止,並出現錯誤,有時該服務在無事可做時會停止。 它在網絡服務帳戶下運行。
我在Windows日志中找不到任何有用的東西。
我嘗試安裝dubug版本並調用debugger.launch(),但無法正常工作。 我不能使用重新調試模式,因為該過程無法保持足夠長的打開時間,我無法對其進行附加。 我真的不知道該怎么辦。 這是我的代碼:
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服務器上運行它。
提前致謝
將您的應用程序重構為控制台應用程序 ,然后在所需的環境中運行它,以便能夠輕松對其進行調試。
我確信一旦以分配給Windows服務的同一用戶帳戶運行控制台副本,問題便會解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.