如果 window 服务已经从 web 服务以编程方式启动,如何接收 window 服务的返回结果

How to receive the returned result of window service if the window service has started programmatically from web service

我在 Web 服务中有 window 服务。我以编程方式从 Web 服务启动了 window 服务。我的问题是如何在网络 service.code 中接收 window 服务的结果以启动 window 服务

ServiceController[] services = ServiceController.GetServices();
        ServiceController service = null;
        foreach (ServiceController Item in services)
        {
            if (Item.DisplayName == "Service1")
            {
                service = new ServiceController("Service1");
                TimeSpan timeout = TimeSpan.FromHours(24);

                service.Start();
                service.WaitForStatus(ServiceControllerStatus.Running, timeout);
                break;
            }
        }

此服务将调用函数 Execute(),它将 return 一个字符串 execution.How 我可以在 Web 服务中接收该字符串吗

简答

你不能。

长答案

以这种方式启动的 windows 服务 运行 在应用程序域中,与 Web 服务所在的域完全隔离 运行。它们也相互隔离.

为了了解这些 windows 服务的内部状态,您需要让它们实现某种远程处理机制(如 Web 服务)或让服务写入某些物理资源,例如文件或数据库。