0

I am trying to see CurrentConnections property in ServicePoint object, but it's returning zero for me always even if I use any public URI; I am using .NET Core. Could someone please tell me if I am missing something?

Here is snippet of my test case:

        IHttpClientFactory clientFactory = serviceProvider.GetService<IHttpClientFactory>();
        HttpClient client = clientFactory.CreateClient();
        var taskList = new List<Task<HttpResponseMessage>>();

        foreach (var item in Enumerable.Range(0, 1000))
        {
            taskList.Add(Task.Run(async () =>
            {
                HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://www.bing.com/");
                ServicePoint servicePoint = ServicePointManager.FindServicePoint(httpRequestMessage.RequestUri); 
                if (servicePoint.CurrentConnections > 0)
                {
                    Assert.Fail($"Found non zero connection = {servicePoint.CurrentConnections}");
                }
                return await client.SendAsync(httpRequestMessage);
            }
            ));
        }
  • That is [as expected](https://github.com/dotnet/runtime/blob/d28b9eebd9fc41539da44b31fcdd5baa590fd351/src/libraries/System.Net.ServicePoint/src/System/Net/ServicePoint.cs#L93). – Hans Passant Jan 24 '20 at 09:41
  • Thanks Hans. I want to report the number of client side service point connections for telemetry purpose. The [doc](https://learn.microsoft.com/en-us/dotnet/api/system.net.servicepoint.currentconnections?view=netcore-2.1) says I should be able to get number of open connections. So, was wondering if I am missing any step. If so, is there any workaround for this to implement in dotnet core? – Bharath R Jan 24 '20 at 23:19

0 Answers0