简体   繁体   English

WCF客户端检查WCF主机是否已启动并正在运行?

[英]WCF Client check if WCF Host is up and running?

I have a wcf service host(console application) and client over netTCPBinding. 我有一个wcf服务主机(控制台应用程序)和netTCPBinding客户端。 In my requirement host goes down and coming up frequently.my client should handle host down and check for host is up for every 1 min .when I am trying to understand and implement that i came across many solutions. 在我的要求主机宕机并经常出现。我的客户应该处理主机,并检查主机是否每1分钟一次。当我试图理解和实现我遇到了很多解决方案。 1. WS-Discovery 2. IsAlive in server 3. Ping method etc. 4. polling 1. WS-Discovery 2.服务器中的IsAlive 3. Ping方法等4.轮询

private static bool IsConnectionUp()
        {
            _logClient = new LogClient();

                try
                {
                    _logClient.Open();
                    return true;
                }
                catch (FaultException exception)
                {
                    if (_logClient.State == CommunicationState.Faulted)
                    {

                        _logClient = new LogClient();
                    }
                    return false;
                }


        }

    Main()
    {
     while (IsConnectionUp()!=true)
                {
                    IsConnectionUp();
                }
    }

the above piece of code good way to do if not please suggest. 上面这段代码好的方法,如果没有请建议。

I want to poll continuously for host from client.which is the best method i can adopt. 我想连续从客户端轮询主机。这是我可以采用的最佳方法。 thanks 谢谢

The existing code leaks connections which is dangerous. 现有代码泄漏了危险的连接。 You need to implement the WCF dispose pattern (which is not the normal pattern due to an API design error by the WCF team). 您需要实现WCF配置模式(由于WCF团队的API设计错误,这不是正常模式)。

Opening a connection does not necessarily test for availability. 打开连接不一定测试可用性。 I don't know what your binding does when opening. 打开时我不知道你的装订是做什么的。 I suspect HTTP-based binding do nothing at all. 我怀疑基于HTTP的绑定什么都不做。 I don't think it's possible to ask the underlying HttpWebRequest infrastructure to open a connection without making a request. 我不认为可以要求底层的HttpWebRequest基础设施在不发出请求的情况下打开连接。

The best way to do this is to implement a test method (eg void Ping() { } ). 执行此操作的最佳方法是实现测试方法(例如void Ping() { } )。 Use a short timeout and dispose resources. 使用短暂超时并处置资源。

The unthrottled loop is dangerous as well. 非节流循环也是危险的。 This is basically a denial of service attack. 这基本上是一种拒绝服务攻击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM