How to disable keep-alive for ASP.NET Web Service client requests?

I have several web servers behind Amazon EC2 balancer. I use TCP balancing on port 80 (instead of HTTP balancing).

I have a client by polling a web service (running on all web servers) for new items every few seconds. However, the client seems to remain connected to the same server and each time it checks the same server.

I tried using ServicePointManager to disable KeepAlive, but that didn't change anything. The outbound connection still had the "connection: keep-alive" HTTP header, and the server supported the TCP connection. I also tried adding the GetWebRequest override to the proxy class created by VS that inherits from SoapHttpClientProtocol, but I still see the keep-alive header.

If I kill the client process and reboot, it will connect to the new server through the load balancer, but it will continue to poll this new server forever.

Is there a way to get it to connect to a random server each time? I want the download from one client to be distributed on all web servers.

The client is written in C # (as on the server) and uses a web link (rather than a service link) that indicates load balancing.

+6
c # web-services keep-alive load-balancing
source share
1 answer

Does not override the GetWebRequest method:

protected override WebRequest GetWebRequest(Uri uri) { var webRequest = (HttpWebRequest)base.GetWebRequest(uri); webRequest.KeepAlive = false; return webRequest; } 
+9
source share

All Articles