Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF-如何检测没有活动连接的情况_C#_Wcf - Fatal编程技术网

C# WCF-如何检测没有活动连接的情况

C# WCF-如何检测没有活动连接的情况,c#,wcf,C#,Wcf,我有一个包含两个组件的解决方案。一个作为系统运行的WCF服务wsDualHttpBinding(WcfService)和一个连接到它的代理(在用户空间中运行的桌面应用程序) 在WCF项目中,实例化web服务的代码如下 WcfService wcfClass = new WcfService(); host = new ServiceHost(wcfKiosk); host.Open(); 在客户端项目中,在 client = new Agent.WcfServiceClient(instanc

我有一个包含两个组件的解决方案。一个作为系统运行的WCF服务wsDualHttpBinding(WcfService)和一个连接到它的代理(在用户空间中运行的桌面应用程序)

在WCF项目中,实例化web服务的代码如下

WcfService wcfClass = new WcfService();
host = new ServiceHost(wcfKiosk);
host.Open();
在客户端项目中,在

client = new Agent.WcfServiceClient(instanceContext);
client.OpenSession();
OpenSession方法只捕获回调值

        public void OpenSession()
        {
            Callback = OperationContext.Current.GetCallbackChannel<IWcfServiceCallback>();
            Console.WriteLine("> Session opened at {0} using credentials {1}", DateTime.Now, System.Threading.Thread.CurrentPrincipal.Identity.Name);
        }
其目的是每X秒检查一次是否存在连接到服务的代理,但我不知道如何做到这一点

我可以尝试实现对系统上运行的代理进程的搜索。如果没有,就启动一个。但我更喜欢更优雅的方式来检查servicehost对象本身,可能是为了连接活动


有什么建议吗?

在WCF中无法检测到客户端已关闭或客户端以某种方式突然被终止。
            System.Timers.Timer checkAgentTimer = new System.Timers.Timer(10000);
            checkAgentTimer.AutoReset = false;
            checkAgentTimer.Elapsed += new System.Timers.ElapsedEventHandler(CheckAgentTimer_Elapsed);
            checkAgentTimer.Start();