1

I have following controller to get JSON data

    [HttpPost]
    [Route("Clients/Active")]
    public IHttpActionResult SearchClient(ClientSearchParams p)
    {
        List<ClientViewModel> _result = PeopleComponent.SearchClient(p).ToList();
        return Ok<IEnumerable<ClientViewModel>>(_result);

    }

Works fine for smaller data (couple of thousand of lines) and returns full formatted JSON but when data is little bigger the response get truncated occasionally but with 200 OK.

Any idea why controller would truncate it randomly. Completely baffled.

  • Webapi has a default maximum request size. It will automatically truncate messages larger than this and give you invalid JSON. You can increase this (are you on full fat .NET, or .NET core?) – Phil S Mar 07 '19 at 16:01

3 Answers3

1

I think your question is related to this issue

I think the worst thing you can do is to return package of data without having an impact on its size so in this, case you should use pagination.

Beyond the pale, I would rather use Dto or Rto to name objects which actions return in your Web API. ViewModels objects are more related to pure ASP.NET MVC architecture and in case of Web API, Clients can use your endpoints using many different ways.

GoldenAge
  • 2,918
  • 5
  • 25
  • 63
0

Webapi has a default maximum request size. It will automatically truncate messages larger than this and give you invalid JSON. Depending on your version of .NET core you can increase this -

For example, in .NET 4.5, you can edit your Web.Config to contain this:

<system.web>
<authentication mode="None" />
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" maxRequestLength="100000"/>
</system.web>
Phil S
  • 642
  • 8
  • 19
0

Thanks all for your help. This line is web.config was real culprit which enables http logging. I turned http logging to false and it works add key="ENABLE_HTTP_LOGGING" value="true" turned it to false and everything works fine.