I'm trying to convert an existing class library code to a .NET Core class library. In that code in a static
constructor I have the following:
ServicePointManager.DefaultConnectionLimit = 100;
ServicePointManager.Expect100Continue = false;
I did some searching and ServicePointManager
is no longer available in .NET Core, and WinHttpHandler
should be used now (ServicePointManager.DefaultConnectionLimit in .net core?).
My question is what exactly is the ServicePointManager
and what are those properties that are being set?
The WinHttpHandler
is not static
as ServicePointManager
so I'd have to create an instance to set those properties? do I need to change all my http calls to make use of that instance?
ServicePointManager is a static class used to create, maintain, and delete instances of the ServicePoint class.
Setting ServicePointManager. SecurityProtocol to TLS 1.2 affects on whole Application Domain and breaks all the other requests and network - based APIs from application that don't support TSL 1.2. Sometimes theese APIs use default settings and your code breaks them.
The DefaultConnectionLimit property sets the default maximum number of concurrent connections that the ServicePointManager object assigns to the ConnectionLimit property when creating ServicePoint objects.
HttpClient connections management in . NET Framework 4.5 and +, the default constructor of HttpClient uses the HttpClientHandler class, which leverages the HttpWebRequest class to send HTTP requests. Therefore, we can use the good old ServicePoint and ServicePointManager classes to manage opened connections.
WinHttpHandler
inherits from HttpMessageHandler
, so you can pass it as a parameter when constructing you HttpClient
like follows:
WinHttpHandler httpHandler = new WinHttpHandler();
httpHandler.SslProtocols = SslProtocols.Tls12;
HttpClient client = new HttpClient(httpHandler);
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With