0
votes

I've deployed a web application using dot net core 2.1 on windows server 2016 which has more than 1000 Requests/Sec.

In one of my actions I'm just calling a web service as below:

byte[] dataBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(some data goes here));

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(my uri);

request.Timeout = 3000;
request.ContentLength = dataBytes.Length;
request.ContentType = "application/json";
request.Method = "POST";

using (Stream requestBody = request.GetRequestStream())
{
    await requestBody.WriteAsync(dataBytes, 0, dataBytes.Length);
}

using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
    return await reader.ReadToEndAsync();
}

After one or two minutes from starting application on server, this method throws exception:

System.Net.WebException: Only one usage of each socket address (protocol/network address/port) is normally permitted

What's the reason of this exception and how can i solve it?

Server spec:

Cpu: 2.67 GHz, VirtualProcessors: 16

RAM: 128 GB

1

1 Answers

0
votes

If you still did not find the answer to this question most likely there is a socket confliction with one of the other services/applications running in your machine.

That usually happens when 2 applications trying to use the same socket address at the same time. Hope this helps.