title: Request doesn't wait for response in .net
body: <p>I have a windows service which is uploading files to the other website which is processing them. The problem is that with small files it's working fine and it's getting response from there, but with large files (about 6 minute to process) it leaves forever in a waiting mode.</p>
  
  <p>Here is the part of external website post method code:</p>
  
  <pre><code>try
  {
    ...
    LogResults();
    return string.Empty;
  }
  catch (Exception e)
  {
    return e.Message;
  }
  </code></pre>
  
  <p>The problem is that I can see logs even for large files, so it means that website always returning value, but for large files my windows service doesn't wait for them.</p>
  
  <p>And here is the code from windows service</p>
  
  <pre><code>var valuesp = new NameValueCollection
  {
       { "AccountId", datafeed.AccountId }
  };
  
  byte[] resultp = UploadHelper.UploadFiles(url, uploadFiles, valuesp);
  response = Encoding.Default.GetString(resultp);
  </code></pre>
  
  <p><code>UploadFiles</code> method returns value for small files, but waiting forever for large ones.</p>
  
  <p>Here is complete code of UploadFiles</p>
  
  <pre><code>public static byte[] UploadFiles(string address, IEnumerable&lt;UploadFile&gt; files, NameValueCollection values)
  {
      var request = WebRequest.Create(address);
      request.Timeout = System.Threading.Timeout.Infinite; //3600000; // 60 minutes
      request.Method = "POST";
      var boundary = "---------------------------" +
                     DateTime.Now.Ticks.ToString("x", NumberFormatInfo.InvariantInfo);
      request.ContentType = "multipart/form-data; boundary=" + boundary;
      boundary = "--" + boundary;
  
      using (var requestStream = request.GetRequestStream())
      {
          // Write the values
          if (values != null)
          {
              foreach (string name in values.Keys)
              {
                  var buffer = Encoding.ASCII.GetBytes(boundary + Environment.NewLine);
                  requestStream.Write(buffer, 0, buffer.Length);
                  buffer =
                      Encoding.ASCII.GetBytes(string.Format("Content-Disposition: form-data; name=\"{0}\"{1}{1}", name,
                                                            Environment.NewLine));
                  requestStream.Write(buffer, 0, buffer.Length);
                  buffer = Encoding.UTF8.GetBytes(values[name] + Environment.NewLine);
                  requestStream.Write(buffer, 0, buffer.Length);
              }
          }
  
          // Write the files
          if (files != null)
          {
              foreach (var file in files)
              {
                  var buffer = Encoding.ASCII.GetBytes(boundary + Environment.NewLine);
                  requestStream.Write(buffer, 0, buffer.Length);
                  buffer =
                      Encoding.UTF8.GetBytes(
                          string.Format("Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"{2}", file.Name,
                                        file.Filename, Environment.NewLine));
                  requestStream.Write(buffer, 0, buffer.Length);
                  buffer =
                      Encoding.ASCII.GetBytes(string.Format("Content-Type: {0}{1}{1}", file.ContentType,
                                                            Environment.NewLine));
                  requestStream.Write(buffer, 0, buffer.Length);
                  requestStream.Write(file.Stream, 0, file.Stream.Length);
                  buffer = Encoding.ASCII.GetBytes(Environment.NewLine);
                  requestStream.Write(buffer, 0, buffer.Length);
              }
          }
  
          var boundaryBuffer = Encoding.ASCII.GetBytes(boundary + "--");
          requestStream.Write(boundaryBuffer, 0, boundaryBuffer.Length);
      }
  
      using (var response = request.GetResponse())
      using (var responseStream = response.GetResponseStream())
      using (var stream = new MemoryStream())
      {
          responseStream.CopyTo(stream);
          return stream.ToArray();
      }
  }
  </code></pre>
  
  <p>What I'm doing wrong here?</p>
  
  <p><strong>EDIT:</strong> Locally it's working even for 7-8 minutes processing. But in live environment doesn't. Can it be related with main app IIS settings? Can it be related with windows service server settings?</p>
  
  <p><strong>EDIT 2:</strong> Remote server web.config httpRuntime settings</p>
  
  <pre><code>&lt;httpRuntime enableVersionHeader="false" maxRequestLength="300000" executionTimeout="12000" targetFramework="4.5" /&gt;
  </code></pre>