HttpWebRequest问题:系统缺少足够的缓冲区空间或因为队列已满

sho*_*123 3 .net c# asp.net httpwebrequest socketexception

我正在使用服务以XML文档的形式提供酒店列表.所有这些在我们的开发服务器上进行测试时都可以正常工作,但是在部署它之后,所有使用它的页面都很短,并且显示以下错误:

An operation on a socket could not be performed because the system lacked
sufficient buffer space or because a queue was full 91.103.175.187:80

Description: An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about the error
and where it originated in the code. 

Exception Details: System.Net.Sockets.SocketException: An operation on a socket
could not be performed because the system lacked sufficient buffer space or
because a queue was full 91.103.175.187:80

Stack Trace: 

[SocketException (0x2747): An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full 91.103.175.187:80]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +305
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +699

[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetResponse() +7859156
Laterooms.Gateway.LateroomsGateway.GetHotelsWithurl(String url)
Laterooms.Gateway.LateroomsGateway.GetHotelsByKeyword(String keyword, String orderBy) 
Laterooms.LateroomsManager.GetHotelsByKeyword(String keyword, String orderBy, String lang)
Run Code Online (Sandbox Code Playgroud)

看到这个之后,我认为这可能是由于请求的数量,所以我实现了缓存,但仍然发生相同的问题.这是我用来输入数据的代码:

    HttpWebRequest request = null;

    Uri uri = new Uri(url);
    request = (HttpWebRequest)WebRequest.Create(uri);
    request.Method = "POST";
    request.AllowWriteStreamBuffering = false;
    request.ContentLength = 0;
    request.KeepAlive = false;

    using (WebResponse response = request.GetResponse())
    {
        using (Stream dataStream = response.GetResponseStream())
        {
            _LateroomsXml.Load(dataStream);
        }
    }
Run Code Online (Sandbox Code Playgroud)

同样,此问题仅发生在我们的实时服务器上.经过几个小时的调试和谷歌搜索,我没有更接近解决这个问题.

任何有关这方面的帮助将不胜感激!

use*_*282 10

请不要使用该修复程序.您的问题是您已禁用alives,因此它为每个请求使用不同的连接,然后在几分钟内无法再次使用该端口.它正在做它应该做的事情.

启用keep-alive,您的问题就会消失.


sho*_*123 2

我最终找到了解决这个问题的方法,以防万一其他人被卡住!

这里

https://support.microsoft.com/en-us/kb/196271

  1. 启动注册表编辑器。

  2. 在注册表中找到以下子项,然后单击“参数”: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

  3. 在“编辑”菜单上,单击“新建”,然后添加以下注册表项:

    值名称:MaxUserPort

    值类型:DWORD

    数值数据:65534

    有效范围:5000-65534(十进制)

    默认值:0x1388(十进制 5000)

  4. 退出注册表编辑器,然后重新启动计算机。

这与一些更好的缓存相结合,因此每次用户加载页面时都不会提取数据,这将防止这种情况再次发生。

  • 这不是一个解决方案,它是一个黑客,它只会推迟问题,直到你面临更高的负载 (2认同)