How to turn off persistent connections for web service calls

左心房为你撑大大i 提交于 2019-12-08 02:09:59

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/4933383/how-to-turn-off-persistent-connections-for-web-service-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!