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

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

问题描述

这是每一个RFC客户端,他们不小心使用每台主机2个以上的连接这些精的RFC任务......

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

微软在Web客户端来实现这一点。我知道,它可以被关闭

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

App.config中:

App.config:

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

(在<一个发现href="http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/1f863f20-09f9-49a5-8eee-17a89b591007">http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/1f863f20-09f9-49a5-8eee-17a89b591007 )

但我怎么能做到这一点编程?

But how can I do it programmatically?

Accordin到 <一href="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit.aspx">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属性对现有的无影响 的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."

我想最好的时候,我实例化的Web客户端,只是去掉这个伤心的限制编程在我PROGRAMM开始就可以了,也配置了极限。

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的调用,但我不使用web服务或远程

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天全站免登陆