I have a WebApi in AspNetCore which is deployed on an Azure App service. The WebApi can only be used for posting an array of objects. The object contains a lot of properties (100+) and 3 object arrays. (it represents a building). The object Arrays can contain over 300 objects each.
When I'm debugging in Visual studio 2017 (15.4.1) the api works fine and accepts all request. When deployed to Azure, it accepts most request. But a few disappear into the void. By that I mean there is no response whatsoever. The requests that go wrong have a lot of objects in one of the arrays. By reducing the amount of objects to a certain number, the request is accepted. As said, in visual studio all requests are being accepted. The data send is solid.
I have created a test controller, with the same interface, but no logics, only response "succes"! On this interface the requests fail as well (same behavior). Newtonsoft(10.0.3) is used by both controllers for deserialization.
What could cause this difference in behaviour with these request?
The code of the controller:
public class TestController : Controller
{
[HttpPost]
[RequireHttps]
public IActionResult Post([FromBody] Buildings Buildings)
{
enumActionResult status = enumActionResult.success;
try
{
if (Buildings == null)
throw new Exception("No valid buildings posted!");
if (Buildings.items == null)
throw new Exception("No valid building items posted!");
if (Buildings.items.Count == 0)
throw new Exception("Zero building items posted!");
return Json(new response() { status = status.ToString(), Buildings = list
}
catch (Exception ex)
{
return Json(new ErrorResponseFormat() { message = ex.Message, status = enumActionResult.error, data = new ErrorResponse(ex) });
}
}
}
Update(2017-12-19): The problem is still there, but is narrowed down to SSL. I created a new controller, which only returns the request:
public class EchoController : Controller
{
[HttpPost]
public IActionResult Post()
{
return new FileStreamResult(Request.Body, Request.ContentType);
}
}
If I make a request with https on the URL which fails, and I fire the exact same request on the http URL it is succesfull. This is the same behaviour I got from the debugger, because that uses http only. So instead of a difference betweeen debugger and the azure cloud environment, the problem appears to be http versus https.
In the meantime I implemented in the config (as suggested by Bruce Chen):
<system.webServer>
<security>
<requestFiltering>
<!-- Measured in Bytes -->
<requestLimits maxAllowedContentLength="4000000000" maxQueryString="100000000"/>
<!-- 1 GB, Byte in size, up to 2GB-->
</requestFiltering>
<access sslFlags="Ssl, SslRequireCert"/>
</security>
</system.webServer>
and upgraded to .NET 4.6.2. At this point still no solution, but the problem appears to be narrowed down.
Update(20-12-2017): I found the following interesting thing: When I send a "Large" request to the (https) api it is lost. But when it is preceded with a small request, both requests are accepted. So it looks like the connection setup with a large request fails.
The webapi is uses a custom domain, https and an IP-whitelist. The client needs to authenticate with a client certifificate. full Webapi config (Yes, I removed the previously requestLimits entry):
configuration>
<connectionStrings>
...
</connectionStrings>
<system.webServer>
<security>
<access sslFlags="Ssl, SslRequireCert"/>
</security>
</system.webServer>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>
And the Client is postman, using certificates. Any thoughts?