My team and I are in the process of implementing a data-layer in our MVC5 project. We are using OData on the Web API/backend code. Everything works great until we start hitting character limitations on our query strings.
For example:
This works:
builder.Function("GetSalesTaxRate")
.Returns<double>()
.CollectionParameter<string>("IdentityField");
[HttpGet]
[ODataRoute("GetSalesTaxRate(IdentityField={ids})")]
public IHttpActionResult GetSalesTaxRate([FromODataUri] IEnumerable <string> ids)
{
double rate = 5.6; // Use a fake number for the sample.
return Ok(rate);
}
http://localhost:123456/api/GetSalesTaxRate(IdentityField=['11-3011','11-2011'])
This does not work:
http://localhost:123456/api/GetSalesTaxRate(IdentityField=['11-3011,11-2011,11-9041,11-1011,11-3111,11-3021,11-9021,11-9032,11-9031,11-9039,11-9033,11-9161,11-9013,11-3031,11-9051,11-9061,11-9071,11-1021,11-3121'])
The error I receive is:
Bad request. HTTP Error 400. The request URL is invalid.
Failed to load resource: the server responded with a status of 400 (Bad Request)
I have tried to use client-side filtering via OData (using $filter mechanism), as well as server-side custom data controller filtering (by passing [FromODataUri] IEnumerable < string > as a parameter to the method). Both have limitations for my situation.
I have unsuccessfully tried the registry setting for [UrlSegmentMaxLength] from the stackoverflow answer here: Bad Request - Invalid URL web api
I have unsuccessfully tried these web.config settings:
<system.web><httpRuntime targetFramework="4.6.1" requestValidationMode="4.0" maxQueryStringLength="2097151" maxUrlLength="10999" relaxedUrlToFileSystemMapping="true" enable="true" />.....
<security><requestFiltering><requestLimits maxQueryString="2097151" maxUrl="10999"/>....
I am trying to get this to work on my local box before deploying to a web server on our network. How can I get this to work locally? How can I get this endpoint to accept the many "IdentityField" values I need to pass in? I have tried to pass it as IEnumerable < string > as well as just a single string. I run into limits on both.
Do I need to approach this differently? I have read to use POST methods, but I am unsure how to do that. I need the ability to pass up to 800 of these "IdentityField" strings to this endpoint (about 10,000 characters). Any suggestions or ideas? Thank you!