WCF减少客户端连接超时 [英] Wcf decrease client connection timeout

查看:201
本文介绍了WCF减少客户端连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运作良好的wcf服务.问题是客户.我有一个小gui,用户应该在其中放置wcf服务所在的IP地址.客户端和服务都在同一网络上,所以如果我无法连接它,是因为我提供了错误的IP地址或防火墙被阻止.无论如何,我该如何缩短时间,以便用户输入错误的IP时不必等待20秒?这是我的app.config文件查找客户端的方式:

I have a wcf service that works fine. The problem is the client. I have a little gui where the user is supposed to place the ip address of where the wcf service is located. Both the client and service are on the same network so if I am not able to connect it is because I provided an incorrect ip address or because the firewall is blocking. Anyways how can I shorten that time so that if the user types the incorrect ip he does not have to wait like 20 seconds? Here is how my app.config file looks for my client:

这是我的客户端app.config文件的外观:

Here is how my client app.config file looks:

    <client>
        <endpoint address="net.tcp://127.0.0.1:41236/" binding="netTcpBinding" 
            bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1"
            name="NetTcpBinding_IService1">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>

编辑

我已将我的app.config文件更新为:

Edit

I have updated my app.config file to:

    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_IService1" sendTimeout="00:00:02" receiveTimeout="00:00:02">
                <security mode="Transport" />
            </binding>
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://10.10.1.154:41236/" 
                  binding="netTcpBinding" 
                  bindingConfiguration="NetTcpBinding_IService1" 
                  contract="ServiceReference1.IService1"

            name="NetTcpBinding_IService1">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>

请注意,我放置了一个故意不存在的ip地址,由于某种原因,程序仍要等待10秒钟...我添加了sendTimeout="00:00:02" receiveTimeout="00:00:02"属性,但仍然无法使用:(

note I am placing an ip address that does not exist on purpose and for some reason the program still waits for like 10 seconds... I added sendTimeout="00:00:02" receiveTimeout="00:00:02" attributes and still did not work :(

这是我收到的错误消息:

Here is the error message that I get:

无法连接到net.tcp://10.10.1.154:41236/.连接 尝试持续时间为00:00:21.0342031. TCP错误代码 10060:连接尝试失败,因为被连接方没有 一段时间后正确响应或建立连接 失败,因为连接的主机无法响应10.10.1.154:41236.

Could not connect to net.tcp://10.10.1.154:41236/. The connection attempt lasted for a time span of 00:00:21.0342031. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.10.1.154:41236.

请注意,它尝试连接21秒钟...我知道我将无法连接,但是如果可以减少连接时间,那会很好.我打算在同一网络上使用该程序...

Note it attempted to connect for 21 seconds... I knew I was not going to be able to connect but it will be nice if I could reduce that time. I am planning to use this program on the same network...

推荐答案

在您的NetTcpBinding_IService1 bindingConfiguration

On your NetTcpBinding_IService1 bindingConfiguration

添加属性sendTimeout="00:00:02"

这会将其减少到2秒.

修改

请使用OpenTimeout="00:00:02",这应该可以.

这篇关于WCF减少客户端连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆