简体   繁体   English

如何在ASP.NET Web服务客户端请求上禁用keep-alive?

[英]How can I disable keep-alive on ASP.NET Web Service client requests?

I have a few web servers behind an Amazon EC2 load balancer. 我在Amazon EC2负载均衡器后面有几个Web服务器。 I'm using TCP balancing on port 80 (rather than HTTP balancing). 我在端口80上使用TCP平衡(而不是HTTP平衡)。

I have a client polling a Web Service (running on all web servers) for new items every few seconds. 我有一个客户端每隔几秒钟轮询一个Web服务(在所有Web服务器上运行)以获取新项目。 However, the client seems to stay connected to one server and polls that same server each time. 但是,客户端似乎保持连接到一台服务器并每次轮询同一台服务器。

I've tried using ServicePointManager to disable KeepAlive, but that didn't change anything. 我已经尝试使用ServicePointManager来禁用KeepAlive,但这并没有改变任何东西。 The outgoing connection still had its "connection: keep-alive" HTTP header, and the server kept the TCP connection open. 传出连接仍然具有“connection:keep-alive”HTTP标头,并且服务器保持TCP连接打开。 I've also tried adding an override of GetWebRequest to the proxy class created by VS, which inherits from SoapHttpClientProtocol, but I still see the keep-alive header. 我还尝试将GetWebRequest的重写添加到由VS创建的代理类中,该代理类继承自SoapHttpClientProtocol,但我仍然看到了keep-alive标头。

If I kill the client's process and restart, it'll connect to a new server via the load balancer, but it'll continue polling that new server forever. 如果我终止客户端进程并重新启动,它将通过负载均衡器连接到新服务器,但它将继续永久轮询该新服务器。

Is there a way to force it to connect to a random server each time? 有没有办法强制它每次都连接到随机服务器? I want the load from the one client to be spread across all of the web servers. 我希望来自一个客户端的负载分布在所有Web服务器上。

The client is written in C# (as is the server) and uses a Web Reference (not a Service Reference), which points to the load balancer. 客户端使用C#编写(与服务器一样)并使用Web引用(不是服务引用),它指向负载均衡器。

Isn't overriding the GetWebRequest method working: 不会覆盖GetWebRequest方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM