title: How can I pass a moderately large volume of data to my Web API app?
body: <p>I've got this code in a Web API Controller:</p>
  
  <pre><code>[Route("{unit}/{begindate}/{enddate}")]
  [HttpPost]
  public void Post(string unit, string begindate, string enddate, 
      [FromBody] string stringifiedjsondata)
  {
      List&lt;ProduceUsageSPResults&gt; _produceUsageList = JsonConvert.DeserializeObject&lt;List&lt;ProduceUsageSPResults&gt;&gt;(stringifiedjsondata);
      string _unit = unit;
      string _begindate = String.Format("{0}01", HyphenizeYYYYMM(begindate));
      string _enddate = GetEndOfMonthFor(enddate);
      string appDataFolder =  
  HttpContext.Current.Server.MapPath("~/App_Data/");
      string htmlStr = ConvertProduceUsageListToHtml(_produceUsageList);
      string htmlFilename = string.Format("produceUsage_{0}_{1}_{2}.html", 
  _unit, _begindate, _enddate); 
      string fullPath = Path.Combine(appDataFolder, htmlFilename);
      File.WriteAllText(fullPath, htmlStr);
  }
  </code></pre>
  
  <p>It works fine when passing only a little bit of (contrived) data from the Client (Winforms app) via the "[FromBody]" arg, like so:</p>
  
  <pre><code>private async Task SaveProduceUsageFileOnServer(string beginMonth, string beginYear, string endMonth, string endYear, DataTable _dtUsage)
  {
      string beginRange = String.Format("{0}{1}", beginYear, beginMonth);
      string endRange = String.Format("{0}{1}", endYear, endMonth);
      HttpClient client = new HttpClient {BaseAddress = new Uri("http://localhost:42176")};
      string dataAsJson = "[{\"ItemDescription\": \"DUCKBILLS, GRAMPS-EIER 70CT  42#\",\"PackagesMonth1\": 1467}]";
      //string dataAsJson = JsonConvert.SerializeObject(_dtUsage);
      String uriToCall = String.Format("/api/produceusage/{0}/{1}/{2}", _unit, beginRange, endRange);
      var content = new FormUrlEncodedContent(new[]
      {
          new KeyValuePair&lt;string, string&gt;("", dataAsJson)
      });
      HttpResponseMessage response = await client.PostAsync(uriToCall, content);
  }
  </code></pre>
  
  <p>However, if I reverse the comments on the assignment to dataAsJson so that it sends the real data, like so:</p>
  
  <pre><code>//string dataAsJson = "[{\"ItemDescription\": \"DUCKBILLS, GRAMPS-EIER 70CT  42#\",\"PackagesMonth1\": 1467}]";
  string dataAsJson = JsonConvert.SerializeObject(_dtUsage);
  </code></pre>
  
  <p>...it fails; there is no err msg; the DataTable (_dtUsage) is serialized to json just fine with the JsonConvert.SerializeObject() method; it's just that there's a "lot" <em>of</em> data (a few thousand records). The client's call to PostAsync() is never reached, and so the server's Post method is never reached.</p>
  
  <p>Is there a workaround that will allow this to succeed when sending more than just a trivial amount of data? I don't really like passing that much data over the wire (currently the client and server are both running locally, but thinking about the situation once deployed), but the other option is to execute the same Stored Procedure from both the client (to generate Excel spreadsheet files there) and from the server (to convert the data to HTML). It seems to be one of those "Catch-22" situations ("impounded if I do, sequestered if I don't").</p>
  
  <h2>UPDATE</h2>
  
  <p>Testing out user3093073's idea, I added this to the system.webServer section of Web.config:</p>
  
  <pre><code>&lt;security&gt;
    &lt;requestFiltering&gt;
      &lt;requestLimits&gt;
        &lt;headerLimits&gt;
          &lt;add header="Content-type" sizeLimit="10000000" /&gt;
        &lt;/headerLimits&gt;
      &lt;/requestLimits&gt;
    &lt;/requestFiltering&gt;
  &lt;/security&gt;
  </code></pre>
  
  <p>(based on what I found <a href="https://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits" rel="nofollow">here</a>, but it's still not working...</p>
  
  <h2>UPDATE 2</h2>
  
  <p>Closer to user user3093073's answer, I also tried this:</p>
  
  <pre><code>&lt;requestFiltering&gt;
     &lt;requestLimits maxAllowedContentLength="10000000"&gt;
       &lt;!--&lt;headerLimits&gt;
         &lt;add header="Content-type" sizeLimit="100" /&gt;
       &lt;/headerLimits&gt;--&gt;
     &lt;/requestLimits&gt;
  &lt;/requestFiltering&gt;
  </code></pre>
  
  <p>...also to no avail.</p>
  
  <h2>UPDATE 3</h2>
  
  <p>Note that I put the code above in every Web.config file in the site, namely:</p>
  
  <pre><code>The Web.config file below the \[ProjectName]\Views folder
  The Web.config file below the \[ProjectName] folder
  The two Web.config files below the \[ProjectName]\Web.config file, namely "Web.Debug.config" and "Web.Release.config"
  </code></pre>
  
  <p>...or, another way of viewing their locations:</p>
  
  <pre><code>\PlatypusReports\Web.config
  \PlatypusReports\Web.config\Web.Debug.config
  \PlatypusReports\Web.config\Web.Release.config
  \PlatypusReports\Views\Webconfig
  </code></pre>
  
  <h2>UPDATE 4</h2>
  
  <p>After being away from this for several days and coming back to it, it now seems plain to me that the "real" data I was trying to pass is a different animal than the phony/test data, which worked.</p>
  
  <p>The test data was a collection of a simple KeyValuePair. The real data, though, is more complex. So when I tried to convert that complex data to a simple KeyValuePair, trouble was sure to follow. So instead of this:</p>
  
  <pre><code>new KeyValuePair&lt;string, string&gt;("", dataAsJson)
  </code></pre>
  
  <p>...I need something like this:</p>
  
  <pre><code>new List&lt;DeliveryPerformanceClass&gt;("", dataAsJson)
  </code></pre>
  
  <p>...but that is not working either; I get several compile errors, such as, "<em>'System.Collections.Generic.List' does not contain a constructor that takes 2 arguments'</em>"</p>
  
  <p>If I remove the first arg so that it's:</p>
  
  <pre><code>new List&lt;DeliveryPerformanceClass&gt;(dataAsJson)
  </code></pre>
  
  <p>...I get other compile errors, such as, "<em>Argument 1: cannot convert from 'string' to 'int'</em>"</p>