在Azure WebApp上的实例上检测到套接字句柄泄漏

时间:2018-02-27 04:29:30

标签: c# azure azure-web-sites

我被困在一个问题上。我收到以下错误消息:

  

无法连接到远程服务器。试图访问   以其访问权限禁止的方式的套接字

在网上搜索并获得Azure支持的帮助后,我发现如果Web App达到azure web app实例的出站连接限制,它会拒绝连接或终止额外的连接。这是打开套接字的图像:

enter image description here

我的应用程序调用第三方WebAPI和WCF服务。我已经编写了代码来调用API后关闭连接。但它对我不起作用。我做了以下代码来调用Web API。

var request = (HttpWebRequest)WebRequest.Create("www.xyz.com");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = false;
request.Headers.Add("Authorization", "Handshake");
byte[] bodyData;
bodyData = Encoding.UTF8.GetBytes(input_data);
request.ContentLength = bodyData.Length;
request.GetRequestStream().Write(bodyData, 0, bodyData.Length);
request.GetRequestStream().Flush();
request.GetRequestStream().Close();

using (var response = request.GetResponse())
{
    using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
    {
       string output_data = reader.ReadToEnd();
    }   

    response.Close();   
}

有人可以指导我如何摆脱这个问题吗?

0 个答案:

没有答案