此方法用于获取远程服务器上的服务状态:
private getServiceStatus(tMsg, exceptionCollection, input)
{
nsDataTypes.GetServiceStatusOutput output = new nsDataTypes.GetServiceStatusOutput();
try
{
nsSEMLib.ServiceControllerEx[] svcs = new nsSEMLib.ServiceControllerEx[] { new nsSEMLib.ServiceControllerEx(input.ServiceName, input.ServerName) };
nsSEMLib.ServiceControllerEx svc = svcs[0];
System.ServiceProcess.ServiceControllerStatus s = svc.Status;
switch (s)
{
case System.ServiceProcess.ServiceControllerStatus.Running:
output.ServiceStatus = nsDataTypes.ServiceStatus.Started;
break;
case System.ServiceProcess.ServiceControllerStatus.Stopped:
output.ServiceStatus = nsDataTypes.ServiceStatus.Stopped;
break;
case System.ServiceProcess.ServiceControllerStatus.Paused:
output.ServiceStatus = nsDataTypes.ServiceStatus.Paused;
break;
default:
output.ServiceStatus = nsDataTypes.ServiceStatus.NotExists;
break;
}
try
{
nsSEMLib.ServiceControllerEx.ServiceStartMode startMode = svc.StartupType;
switch (startMode)
{
case nsSEMLib.ServiceControllerEx.ServiceStartMode.Automatic:
output.ServiceStartMode = nsDataTypes.ServiceStartMode.Automatic;
break;
case nsSEMLib.ServiceControllerEx.ServiceStartMode.Manual:
output.ServiceStartMode = nsDataTypes.ServiceStartMode.Manual;
break;
case nsSEMLib.ServiceControllerEx.ServiceStartMode.Disabled:
output.ServiceStartMode = nsDataTypes.ServiceStartMode.Disabled;
break;
case nsSEMLib.ServiceControllerEx.ServiceStartMode.Default:
output.ServiceStartMode = nsDataTypes.ServiceStartMode.Default;
break;
default:
output.ServiceStartMode = nsDataTypes.ServiceStartMode.Default;
break;
}
}
catch (Exception ex)
{
}
}
catch (Exception ex)
{
output.ServiceStatus = nsDataTypes.ServiceStatus.NotExists;
ex = null;
}
return output;
}
在调试期间,代码到达这一点:
System.ServiceProcess.ServiceControllerStatus s = svc.Status;
我收到此错误:
ex = {“在计算机上找不到服务NGArchivalEP_002 '服务器名'。“}
但是,如果我检查此服务器,我可以看到服务存在,但它处于停止状态。因此,我的应用程序应该已经读取服务已停止并在网页上描述,而不是生成错误。我认为这与我们最近发布的ID更改有关,但我如何找到我的Web应用程序用于连接这些远程服务器的ID?它是应用程序池中定义的Id吗?