Windows服务在Windows 7上启动,但无法在Windows Server 2008 R2上启动
我创建了一个通过托管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服务器上运行。
在此先感谢
重构您的应用程序作为控制台应用程序,然后在需要的环境中运行,它能够轻松地调试。
我敢肯定,这个问题就会发现自己,一旦你分配给你的windows服务
所以你不认为有一个problrm与服务,但与内容。 ok会这样做 – Ares 2012-03-07 20:14:40
当你完成时分享结果 – CSharpenter 2012-03-07 20:17:06
有关你的错误的任何消息?您是否创建了Console Replica? – CSharpenter 2012-03-08 12:57:51
你不处理的第一个例外相同的用户帐户下运行控制台的副本,这个问题可能发生在那里。 – vulkanino 2012-03-07 16:04:18
我已经尝试删除整个错误日志的东西,仍然是相同的 – Ares 2012-03-07 16:59:48
这似乎并没有在Windows 7中的问题,并在之前所述的调试器不会启动! – Ares 2012-03-07 17:09:00