I used to use HttpWebRequest.ServicePoint.ConnectionLimit (http://msdn.microsoft.com/en-us/library/system.net.servicepoint.connectionlimit(v=vs.110).aspx) to configure number of TCP connections opened by client.
I am planning to use HttpCLient for my new Application. However I couldn't find related information on how to configure number of TCP connections. I thought it would be exposed through one of the properties in webrequesthandler (http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.aspx, Allowing Untrusted SSL Certificates with HttpClient) however I couldn't find it. Looks like it can't be configured through a custom httpclient message handler as well (http://www.asp.net/web-api/overview/advanced/httpclient-message-handlers)
Question
How to configure number of TCP (persisted) connections?
Update 1
Looks like it is not exposed through HttpClient (after analyzing the code through ILSpy). However, looks like i can use FindServicePoint method of ServicePointManager. Can any one please confirm if this is the way to go - by finding the service point for my uri and setting the connection limit?
public static ServicePoint FindServicePoint(Uri address)
{
return ServicePointManager.FindServicePoint(address, null);
}
Update 2
In fact, looks like that is the way to go as HttpWebRequest.ServicePoint
internally is invoking the same method. Below is the corresponding code snippet from ILSpy - however there are quite a few servicepointmanager.findservicepoint(..)
overload methods - picking the right one may be tricky.
Monitor.Enter(this, ref flag);
if (this._ServicePoint == null || forceFind)
{
if (!this.ProxySet)
{
this._Proxy = WebRequest.InternalDefaultWebProxy;
}
if (this._ProxyChain != null)
{
this._ProxyChain.Dispose();
}
this._ServicePoint = ServicePointManager.FindServicePoint(this._Uri, this._Proxy, out this._ProxyChain, ref this._AbortDelegate, ref this.m_Aborted);
if (Logging.On)
{
Logging.Associate(Logging.Web, this, this._ServicePoint);
}
}
Note
I do not want to use ServicePointManager.DefaultConnectionLimit
as it's global. I am looking for something related to httpwebrequest.servicepoint.connectionlimit
which is local to the request and effects per service point (host).