How to set ServicePointManager.DefaultConnectionLimit on a portable system

I need to use multiple tasks that will hit the webservice endpoint. Each task will transmit streams of data and an httpWebRequest connection will be opened.

I need to set the ServicePointManager.DefaultConnectionLimit property to a value greater than 2, but I'm using a portable framework and the ServicePointManager class is not available (must be in System.Net).

How do I allow more open web requests in a portable environment?

Sincerely.

+3


source to share


1 answer


I couldn't find a way to have more than two connections using webrequest objects in a portable environment, but I found a way to have more parallel connections. I am just using the HttpClient class.

In my tests, when using HttpClient, you can use more than two concurrent connections. I tried 10 and it works fine.

The following test contains 10 parallel connections:



   var clients = new List<System.Net.Http.HttpClient>();

        for (int i = 0; i < 10; i++)
        {
            var client = new System.Net.Http.HttpClient();

            var response = client.GetAsync("http://www.google.com").Result;

            clients.Add(client);
        }
        foreach (var client in clients)
            client.Dispose();

      

This is a workaround. My original question, however, remains unanswered.

0


source







All Articles