I have a web API controller with a POST method as follows.
public class MyController : ApiController
{
// POST: api/Scoring
public HttpResponseMessage Post([FromBody]MyClass request)
{
// some processing of request object
return Request.CreateResponse(HttpStatusCode.OK, someResponseObject);
}
....
}
This is consumed by a HTTPClient as follows
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.BaseAddress = new Uri("http://localhost");
MyClass requestClient = new MyClass();
var task = httpClient.PostAsJsonAsync("api/my", requestClient)
It works great when MyObject object size passed in POST method parameter of controller is small in size. However in case when this object size is big, I get a null for the request object in the POST method parameters. In one case, the size of the requestClient object passed from client side request is ~5 MB and in the POST method, I get request object as null. Note that Web API is hosted under IIS. Is there any setting that I need to change for permissible size.
UPDATE: Adding following in web.config solved the null object issue in the POST method parameter.
httpRuntime maxRequestLength="2147483647" />
I then increased the size of requestClient object to ~50MB. Now the code in POST method never getting hit. On the client side, at the call to PostAsJsonAsyn, I get System.Net.HttpRequestException with following message.
Response status code does not indicate success: 404 (Not Found).
Now changing maxRequestLength doesn’t seem to have any impact.