title: Socket handle leak happening on Azure Web App
body: <p>I have been stuck in one issue. I am getting error of "Unable to connect to the remote server. An attempt was made to access a socket in a way forbidden by its access permissions".</p>
  
  <p>After searching on web and taking help of azure support, I came to know that if Web App reaches outbound connection limit of azure web app instance, it refuses connections or kill extra connections. Here is the <a href="https://i.stack.imgur.com/EgfOM.png" rel="nofollow noreferrer">image</a> of open socket handles</p>
  
  <p>My application calls third party WebAPI and wcf service. I have written code to close connections after making call to APIs. but it doesn't work for me. I did following code to call Web API.</p>
  
  <pre><code>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();   
   }
  </code></pre>
  
  <p>Could anyone guide me how to get rid on this issue?</p>