简体   繁体   中英

Why can't I prevent chunking on my HttpRequest from WPF client to Web API controller?

I have been battling this for a week now. See my previous question for some additional background.

My WPF client makes GET , POST and PUT calls to my Web API controllers. All was well for weeks. Then suddenly, all of my PUT and POST calls are coming in chunked. I cannot find any means of preventing it. I strongly suspect I made one central change that impacted everything, but I am exhausted trying to find it. I've looked back through source control and reinstated old code, and it just refuses to work.

I know of "request.Headers.TransferEncodingChunked" and it has no effect. I can explicity set it to null or false in my client, and it always arrives in my routine below as true .

My PUT/POST controller methods follow this model. The upshot for me is that my incoming objects ("User" here) arrive as null. But if I do a .ReadAsStringAsync() on the request, I get exactly the JSON expected. But I don't want to rearchitect this app around that non-intuitive pattern; the blasted objects should just arrive unchunked and ready for work!

[HttpPut]
[ResponseType(typeof(User))]
public IHttpActionResult Put([FromBody] User user)
{
    if (user == null)
        return Content(HttpStatusCode.BadRequest, "User data is null");

    try
    {
        ....etc.
    }
}

The "User" object is an Entity Framework object, and is unremarkable. Simple string, DateTime and numeric properties.

Similarly, and just as infuriating, I can set request.Headers.AcceptEncoding to null and it arrives in my controller as Accept-Encoding: gzip, deflate .

Some links that describe the same problem and symptoms:

No clear answer on this, but I finally got it fixed. It was a long haul.

Don't know how it got there, but in my .csproj I had this:

<Reference Include="System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
    <HintPath>..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll</HintPath>
    <Private>True</Private>
</Reference>

Rather than this:

<Reference Include="System.Net.Http" />  

And in my App.config I had this:

<dependentAssembly>
  <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>

...rather than... not this. I didn't need this stuff. I just took it out and it all started working again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM