System.Net.WebException:通常只允许使用每个套接字地址(协议/网络地址/端口)

问题描述 投票:0回答:1

我已经在Windows Server 2016上使用dot net core 2.1部署了一个Web应用程序,它具有超过1000个请求/秒。

在我的一个操作中,我只是调用Web服务,如下所示:

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();
}

在服务器上启动应用程序一到两分钟后,此方法抛出异常:

System.Net.WebException:通常只允许使用每个套接字地址(协议/网络地址/端口)

这个例外的原因是什么,我该如何解决?

服务器规格:

Cpu:2.67 GHz,VirtualProcessors:16

RAM:128 GB

c# asp.net .net .net-core
1个回答
0
投票

如果您仍未找到此问题的答案,则很可能与您计算机中运行的其他服务/应用程序之一存在套接字冲突。

当两个应用程序试图同时使用相同的套接字地址时,通常会发生这种情况。希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.