5
votes

I am migrating a console app (REST client app) from .NET framework to .NET Core.

In my current (framework) version, I use the app.config file to set the System.Net configuration:

<system.net>
    <connectionManagement>
      <add address="*" maxconnection="65535"/>
    </connectionManagement>
</system.net>

In .NET Core, I have to use a JSON file for configuration. There is no documentation for implementing these settings using the new configuration schema. Does anyone know how this might look inside the new JSON config, or the correct way to implement this in Core? Do I need to build a designated "System.Net.json" config file (separate from an AppSettings.json) specifically to do this?

Thanks.

3

3 Answers

1
votes

Assuming you are using Kestrel as your web server (and not doing it through IIS implementation), you should be able to set this in your UseKestrel in your BuildWebHost.

It would go something like this:

.UseKestrel(options =>
{
    options.Limits.MaxConcurrentConnections = 100;
})

You can also add this in your HttpClientHandler, It's called MaxConnectionsPerServer. It can be seen here.

11
votes

I assume you're trying to avoid the limit of 2 connections per endpoint, which is default on .NET Framework. Such limit does not exist on .NET Core. So you don't need the above setting at all.

Note that to achieve better perf, we recommend to use HttpClient/HttpClientHandler over HttpWebRequest/ServicePoint on .NET Core. HttpWebRequest/ServicePoint APIs are compat-only.

If you want to limit HttpClient connections, then use HttpClientHandler.MaxConnectionsPerServer

0
votes

Some addition to Karel Zikmund answer. (As i don’t have permissions to comment).

According to this doc connections are limited since .net core 2.0: https://docs.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager.defaultconnectionlimit?view=netcore-3.1

What is missed in doc is if ServicePointManager used for .net core HttpClient implementation. According to this info it is used in .net core, but for HttpWebRequest, not HttpClient: https://github.com/dotnet/runtime/issues/26048