开发者

How to turn off persistent connections for web service calls

开发者 https://www.devze.com 2023-02-09 01:08 出处:网络
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

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 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.

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.

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


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号