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

4

I am passing a list of objects to my API in C #. When the list size is smaller, everything happens as it should. When the list is a bit larger the list comes empty in my API.

When the list is smaller I get the expected result:

HoweverwhenIsendthislist:

Igetthisresult:

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

    
asked by anonymous 25.10.2017 / 15:15

2 answers

1

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

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

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

  

When request filtering blocks an HTTP request, IIS   7 will return an HTTP 404 error to the client and register the HTTP status with   a unique substatus that identifies the reason why the request   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.config

// limita o POST para 10MB, query string para 256 chars, url para 1024 chars
<requestLimits maxQueryString="256" maxUrl="1024" maxAllowedContentLength="102400000" />
    
27.10.2017 / 13:00
1

Try to send this:

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 reply, 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

    
25.10.2017 / 21:20