正在从 Asp.net Web 应用程序执行 Windows 服务 (*.exe)
Executing Windows Service (*.exe) from Asp.net Web Application
我已经在我的系统中创建了 Windows 服务并安装了 .exe
文件。我可以在 windows 10.
上从 Service
控制 运行 此服务
我运行正在从 ASP.NET 网络应用程序中使用相同的服务。服务已启动,但我想在从 Web 应用程序调用时调用 protected override void OnCustomCommand(int command)
方法。
我收到
的错误
An exception of type 'System.InvalidOperationException' occurred in System.ServiceProcess.dll but was not handled in user code
Additional information: Cannot control ServiceName service on computer '.'.
网页上调用windows服务的代码如下-
ServiceController sc = new ServiceController("ServiceName");
if (sc.Status != ServiceControllerStatus.Running && sc.Status != ServiceControllerStatus.StopPending)
{
TimeSpan timeout = TimeSpan.FromMilliseconds(60000);
sc.Start();
sc.ExecuteCommand(CommandId);
sc.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
任何人都可以帮助找出这个问题的原因吗?
网页代码运行没有管理员权限来控制该机器上的服务。
您必须将您的应用程序池配置为 运行 在管理帐户下。从安全的角度来看,这可能不是一个好主意。
如果您不想 运行 您的网络应用程序具有管理权限,您可以考虑在您的 windows 服务中托管您自己的侦听器,它只需要 username/password 或者也许根本没有身份验证,因为您选择了仅对本地主机可用的变体。 WCF 可能是一个不错的选择,或者 ASP.NET 如果您对此更熟悉的话。
我已经在我的系统中创建了 Windows 服务并安装了 .exe
文件。我可以在 windows 10.
Service
控制 运行 此服务
我运行正在从 ASP.NET 网络应用程序中使用相同的服务。服务已启动,但我想在从 Web 应用程序调用时调用 protected override void OnCustomCommand(int command)
方法。
我收到
的错误An exception of type 'System.InvalidOperationException' occurred in System.ServiceProcess.dll but was not handled in user code
Additional information: Cannot control ServiceName service on computer '.'.
网页上调用windows服务的代码如下-
ServiceController sc = new ServiceController("ServiceName");
if (sc.Status != ServiceControllerStatus.Running && sc.Status != ServiceControllerStatus.StopPending)
{
TimeSpan timeout = TimeSpan.FromMilliseconds(60000);
sc.Start();
sc.ExecuteCommand(CommandId);
sc.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
任何人都可以帮助找出这个问题的原因吗?
网页代码运行没有管理员权限来控制该机器上的服务。
您必须将您的应用程序池配置为 运行 在管理帐户下。从安全的角度来看,这可能不是一个好主意。
如果您不想 运行 您的网络应用程序具有管理权限,您可以考虑在您的 windows 服务中托管您自己的侦听器,它只需要 username/password 或者也许根本没有身份验证,因为您选择了仅对本地主机可用的变体。 WCF 可能是一个不错的选择,或者 ASP.NET 如果您对此更熟悉的话。