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