[英]WCF Duplex clients with different data from the service
我正在尝试编写一个Web服务,该服务将流程的输出传达给所有监听的客户端。 这似乎是故障代码。 该应用程序应该启动一个进程,然后监听输出。 在StartWebServer
情况下,客户端调用StartWebServer
并且该进程已经在运行,在这种情况下,该功能不应再次启动该进程,而应将该客户端订阅接收输出(中断)的客户端列表。
问题似乎是当第二个客户端调用StartWebServer
,指定端口上的进程列表与另一个客户端的列表不同。
该行在另一个客户端使用相同的端口作为参数的第二次调用中返回false: !Processes.ContainsKey(port)
Dictionary<int, List<IBatchServiceCallback>> Processes =
new Dictionary<int, List<IBatchServiceCallback>>();
public void StartWebServer(int port)
{
//Start the webserver (if it's not already running) and listen to the output
//Start process if not already running
if (!Processes.ContainsKey(port)) // returns false on second call
{
int pid = catalina("run"); // Start process
if (pid < 0) return;
Processes.Add(port, new List<IBatchServiceCallback>());
}
//Listen to process whether or not I started it
ListenTo(port);
}
弄清楚了,我只需要变量是静态的:
private static Dictionary<int, List<IBatchServiceCallback>> Processes =
new Dictionary<int, List<IBatchServiceCallback>>();
和标签:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class BatchService : IBatchService
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.