我如何以编程方式删除WebClient中的2连接限制 [英] How can I programmatically remove the 2 connection limit in WebClient

查看:188
本文介绍了我如何以编程方式删除WebClient中的2连接限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些精细RFC要求每个RFC客户端,他们意识到每个主机不使用多于2个连接...

Those "fine" RFCs mandate from every RFC-client that they beware of not using more than 2 connections per host...

Microsoft在WebClient中实现了这一点。我知道它可以通过

Microsoft implemented this in WebClient. I know that it can be turned off with

关闭。

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

但我该如何以编程方式呢?

But how can I do it programmatically?

Accordin到
http:// msdn。 microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit.aspx

Accordin to http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit.aspx

更改DefaultConnectionLimit属性对现有的$ b没有影响$ b ServicePoint对象;它只影响在更改之后初始化的
的ServicePoint对象。如果此属性的值未直接或通过配置设置为
,则该值默认为
常量DefaultPersistentConnectionLimit。

"Changing the DefaultConnectionLimit property has no effect on existing ServicePoint objects; it affects only ServicePoint objects that are initialized after the change. If the value of this property has not been set either directly or through configuration, the value defaults to the constant DefaultPersistentConnectionLimit."

我想最好配置限制当我实现WebClient,但只是删除这个悲伤的限制程序化在我的程序的开始将是很好的

I'd like best to configure the limit when I instanciate the WebClient, but just removing this sad limitation programmatically at the start of my programm would be fine, too.

我访问的服务器不是互联网中的常规网络服务器,但在我的控制下和本地局域网中。我想要执行API调用,但我不使用webservices或remoting

The server I access is not a regular webserver in the internet, but under my control and in the local lan. I want to do API-calls, but I don't use webservices or remoting

推荐答案

管理通过覆盖我使用的WebClient类在我的应用程序中修复这个问题:

With some tips from here and elsewhere I managed to fix this in my application by overriding the WebClient class I was using:

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

这篇关于我如何以编程方式删除WebClient中的2连接限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆