这些"好"Rfc任务期限从每RFC-客户,他们注意不使用超过2个连接的每主机...

Microsoft实现这Web客户端.我知道,它可以关闭

应用程序。配置:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
 <system.net> 
  <connectionManagement> 
   <add address="*" maxconnection="100" /> 
  </connectionManagement> 
 </system.net> 
</configuration> 

(上找到的 http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/1f863f20-09f9-49a5-8eee-17a89b591007 )

但我怎么可以做的编程方式?

向根据客户的要求。 http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit.aspx

"改变DefaultConnectionLimit酒店没有任何影响现有的 ServicePoint对象;它仅影响ServicePoint的对象 初始化之后的变化。如果这个酒店没有 设置直接或通过结构中,值默认的 恒DefaultPersistentConnectionLimit."

我想最佳配置的限制,当我instanciate Web客户端,但是只是删除这个悲伤的限制程开始时我领会好的,太。

服务器的访问是不是正规的网络服务器在互联网上,但是在我的控制和在当地的局域网。我想要做的API-电话,但我不使用web服务或远程处理

有帮助吗?

解决方案

从这里和其他地方的一些技巧,我设法在我的应用程序来解决这个问题通过重写我使用WebClient类:

class AwesomeWebClient : WebClient {
    protected override WebRequest GetWebRequest(Uri address) {
        HttpWebRequest req = (HttpWebRequest)base.GetWebRequest(address);
        req.ServicePoint.ConnectionLimit = 10;
        return (WebRequest)req;
    }
}

其他提示

对于那些有兴趣:

System.Net.ServicePointManager.DefaultConnectionLimit = x(其中x是所期望的连接的数量)

不需要额外的引用

只要确保如在上述讯息中提到之前创建的服务点这被称为

这种方案可以让你改变的连接限制在 任何时间:

private static void ConfigureServicePoint(Uri uri)
{
    var servicePoint = ServicePointManager.FindServicePoint(uri);

    // Increase the number of TCP connections from the default (2)
    servicePoint.ConnectionLimit = 40;
}

第1次任何人都叫这个 FindServicePoint, , ServicePoint 实例是创建一个 WeakReference 是为了坚持它的内部 ServicePointManager.随后请求对管理者用于同一Uri返回同一个实例。如果连接不用之后,GC清理它。

如果您发现的ServicePoint对象正在使用你的Web客户端,您可以更改其连接限制。 HttpWebRequest的对象有一个访问来获取他们建造使用一个,所以你可以这样做的。如果幸运的话,你的所有请求最终可能会共享相同的ServicePoint所以你只需要做一次。

我不知道任何全球性的方式来改变限制。如果您在执行改变了DefaultConnectionLimit足够早,你可能会被罚款。

另外,还可以将就着用连接限制,因为大多数服务器软件将反正你掐死。 :)

我们具有关于App.Config中上述片结构的情况                       

为了为这是在一个控制台应用程序有效, 我们增加了System.Configuration参考DLL。 没有参考,以上是无用的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top