C# WCF访问Windows服务错误
我有一个web应用程序asp.net,它调用WCF C。WCF调用Windows服务来执行任务。不幸的是,当WCF调用windows服务时,我得到的错误是 无法在计算机“”上打开appservice服务 WebApp、WCF和appservice都是Windows 2012的同一台机器。WebApp、WCF和appservice正在添加到管理员组的帐户acctname下运行 appservice正在运行,只是WCF无法调用appservice。 你知道怎么解决这个问题吗 下面是WCF中的示例代码,它调用windows服务appserviceC# WCF访问Windows服务错误,c#,asp.net,wcf,windows-services,C#,Asp.net,Wcf,Windows Services,我有一个web应用程序asp.net,它调用WCF C。WCF调用Windows服务来执行任务。不幸的是,当WCF调用windows服务时,我得到的错误是 无法在计算机“”上打开appservice服务 WebApp、WCF和appservice都是Windows 2012的同一台机器。WebApp、WCF和appservice正在添加到管理员组的帐户acctname下运行 appservice正在运行,只是WCF无法调用appservice。 你知道怎么解决这个问题吗 下面是WCF中的示例代码
try
{
string serviceName = "appservice ";
ServiceController niuService = new ServiceController(serviceName);
niuService.MachineName = ConfigurationManager.AppSettings["SERVICE_MACHINE_NAME"];
if (niuService == null)
{
returnObject.IsSuccessful = false;
returnObject.MessageCollection.Add(new Message{Description = "Service <" + serviceName +
"> ON Machine <" + niuService.MachineName + "wasn't found when starting fl"});
}
else if (niuService.Status != ServiceControllerStatus.Running)
{
returnObject.IsSuccessful = false;
returnObject.MessageCollection.Add(new Message{Description = "Service <" + serviceName +
"> wasn't running when starting fl"});
}
else
{
niuService.ExecuteCommand((int)ServiceCustomCommands.START_FL);
returnStatus = true;
returnObject.IsSuccessful = true;
returnObject.BusinessObject = true;
}
}
Windows服务通常不是交互式应用程序。你能提供更多的信息,或者一些代码示例来说明你想要实现的目标吗?请提供更多信息:你如何准确地调用Windows服务?你得到了什么确切的错误?我用每个请求的示例代码更新了我的帖子。你能发布相关的Windows服务代码吗?您是否覆盖了服务中的OnCustomCommand?我还添加了相关的windows服务代码?
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
EventLogEntryType status = EventLogEntryType.Information;
bool cmdUnknown = false;
bool resp = false;
switch (command)
{
case (int)ServiceCustomCommands.CHECK_DB_CONN:
resp = ApiFlashing.Instance.CheckDBconnection();
break;
case (int)ServiceCustomCommands.START_FL:
resp = flON = ApiFlashing.Instance.StartFlashing(0);
break;
//remaining code comes here