如何关闭为Web服务调用持久连接 [英] How to turn off persistent connections for web service calls

查看:250
本文介绍了如何关闭为Web服务调用持久连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的WinForms应用程序,我得叫web服务和我使用一个Web引用。没有问题,到目前为止,但现在我有一个使用代理服务器后面是负载平衡器后面的软件客户端。

From my WinForms application I have to call a webservice and I am using a web reference for that. No problems so far, but now I have a client that uses the software behind a proxy that is behind a load balancer.

Webservice的调用就要罚款,但两分钟后他们失败。我们可以解决此通过反复调用带有间隔不到两分钟一个Web服务。

Webservice calls are going fine, but after two minutes they fail. We can work around this by repeatedly calling a webservice with an interval less than two minutes.

我原来负载平衡器断开TCP会话时,不用于两个他们分钟,appearantly这是在我们的情况会发生什么和sofware无法收回。

I turns out that the load balancer disconnects tcp sessions when they are not used for two minutes, appearantly this is what happens in our case and the sofware is unable to recover.

我如何告诉gerenated Web引用用于每一个网站一个新的TCP连接服务电话?

How do I tell the gerenated web reference to use a new tcp connection for every web service call?

推荐答案

如果你忽略你的代理的 GetWebRequest 方法,那么你可以设置的KeepAlive 属性:

If you override the GetWebRequest method of your proxy, then you can set the KeepAlive property:

public override WebRequest GetWebRequest(Uri uri)
{
    HttpWebRequest request = (HttpWebRequest) base.GetWebRequest(uri);
    request.KeepAlive = false;
    return request;
}

这篇关于如何关闭为Web服务调用持久连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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