title: The request was aborted: The connection was closed unexpectedly
body: <p>I am using Jon Skeet's ReadFully method implemented here:</p>
  
  <pre><code>public static byte[] ReadFully(Stream stream)
  {
      var buffer = new byte[32768];
      using (var ms = new MemoryStream())
      {
          while (true)
          {
              int read = stream.Read(buffer, 0, buffer.Length);
              if (read &lt;= 0)
                  return ms.ToArray();
              ms.Write(buffer, 0, read);
          }
      }
  }
  </code></pre>
  
  <p>It throws an exception at the line:</p>
  
  <pre><code>int read = stream.Read(buffer, 0, buffer.Length);
  </code></pre>
  
  <p>The error message is <code>The request was aborted: The connection was closed unexpectedly</code>.</p>
  
  <p>I am sending an xml request to a webservice.  My send method looks like this:</p>
  
  <pre><code>private static string SendRequest(XElement request, string url)
  {
      var req = (HttpWebRequest)WebRequest.Create(url);
      req.ContentType = "application/soap+xml;";
      req.Method = "POST";
      req.KeepAlive = false;
      req.Timeout = System.Threading.Timeout.Infinite;
      req.ReadWriteTimeout = System.Threading.Timeout.Infinite;
      req.ProtocolVersion = HttpVersion.Version10;
      req.AllowWriteStreamBuffering = false;
  
      using (var stm = req.GetRequestStream())
      {
          using (var stmw = new StreamWriter(stm))
          {
              stmw.Write(request.ToString());
          }
      }
  
      Stream responseStream;
      using (var webResponse = req.GetResponse())
      {
          responseStream = webResponse.GetResponseStream();
      }
  
      // Do whatever you need with the response
      var myData = ReadFully(responseStream);
      string responseString = Encoding.ASCII.GetString(myData);
  
      return responseString;
  }
  </code></pre>
  
  <p>I tried without and without the following variables set and it gives me the same message:</p>
  
  <pre><code>req.KeepAlive = false;
  req.Timeout = System.Threading.Timeout.Infinite;
  req.ReadWriteTimeout = System.Threading.Timeout.Infinite;
  req.ProtocolVersion = HttpVersion.Version10;
  req.AllowWriteStreamBuffering = false;
  </code></pre>