How to pass a large list of objects to API in C#?

I'm passing a list of objects to my API in C#. When the list size is smaller, everything goes as it should. When the list is a little larger the list arrives empty in my API.

When the list is smaller I get the expected result:

With a smaller list it all works out

However when I send this list:

Array command

I get this result:

Empty object list

Could anyone explain to me why and how to solve this problem?

Author: Welber Silverio, 2017-10-25

2 answers

You can modify the element httpRuntime in the web file.config by adding the following attribute. This should solve the problem of the object having null value when running the POST.

// limite para o buffer de fluxo de entrada, em kilobytes
<httpRuntime maxRequestLength="2147483647" />

However, you may have problems with request filtering introduced in iis version 7.0. More specifically (my translation):

When request filtering blocks an HTTP request, IIS 7 will return an HTTP 404 error to the client and will record HTTP status with a unique substatus that identifies the reason why the request it was denied.

+----------------+------------------------------+
| HTTP Substatus |         Descrição            |
+----------------+------------------------------+
|          404.5 | Sequência URL Negada         |
|          404.6 | Verbo Negado                 |
|          404.7 | Extensão de arquivo Negada   |
|          ...   |                              |

To resolve this limitation, you can modify the <requestLimits> element within the web file.config

// limita o POST para 10MB, query string para 256 chars, url para 1024 chars
<requestLimits maxQueryString="256" maxUrl="1024" maxAllowedContentLength="102400000" />
 1
Author: mercador, 2017-10-27 11:00:53

Try sending this way:

public JsonResult PdfSellout(List<SellOut> sellout)
{
        var lista = buscarLista();
        var jsonResult = Json(lista, JsonRequestBehavior.AllowGet);
        jsonResult.MaxJsonLength = int.MaxValue;
        return jsonResult;
}

Edit: The above method is for response, for sending files use the following:

var httpClient = new HttpClient();

httpClient.DefaultRequestHeaders.TransferEncodingChunked = true;

var content = new CompressedContent(new StreamContent(new FileStream("c:\\big-json-file.json",FileMode.Open)),"UTF8");

var response = httpClient.PostAsync("http://example.org/", content).Result;

For a large string use this link

For a list of objects, use this link

 1
Author: Walter Junior, 2017-10-25 19:31:48