Ismail Siddiqui
Ismail Siddiqui

Reputation: 43

Web API 2 Json output getting truncated

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.

Upvotes: 1

Views: 2102

Answers (3)

Ismail Siddiqui
Ismail Siddiqui

Reputation: 43

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.

Upvotes: 0

GoldenAge
GoldenAge

Reputation: 3068

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.

Upvotes: 1

Phil S
Phil S

Reputation: 846

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>

Upvotes: 0

Related Questions