Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData Url Length Limitations

Tags:

odata

Browsers have limitation on the length of the URLs. IE has limitation that Url length should not exceed 2K characters.

When I form a $filter equals query, I could compare with multiple input values. In such a case the length of the Url would exceed 2K.

Does OData sets any limits on the length of the Url?

Thanks

like image 533
Venki Avatar asked Nov 22 '10 16:11

Venki


People also ask

What is the length limit for URLs?

The official documentation specifies a maximum length of 2048 characters for the <loc> element, which is used to submit URLs: URL of the page. This URL must begin with the protocol (e.g. “http”) and end with a trailing slash if required by the web server. This value must not exceed 2,048 characters.

What is OData service URL?

URL Components A URL used by an OData service has at most three significant parts: the service root URL, resource path and query options. Additional URL constructs (such as a fragment) MAY be present in a URL used by an OData service; however, this specification applies no further meaning to such additional constructs.

How do I find OData service URL?

If you have an on-premise system, then call /N/IWFND/MAINT_SERVICE, choose your service, click on Gateway Client, set the protocol to HTTPS and you'll see the full URL.


2 Answers

OData itself doesn't limit the length of the Url, but as you noted most clients and servers do. So usually it's a good practive to not produce URLs too long.

The problem you refer to (implementing the Contains operator, or something similar) has two possible workarounds:

1) Use service operation to handle such query for you. You can possibly pass the multiple input values encoded as a string or something like that, or maybe the service operation knows these up front anyway.

2) Use the long $filter, but send the request in a $batch request. The advantage is that the limit on the Url is much bigger and it's very unlikely you will hit it. The disadvantage is that even though you're trying to execute a GET request, due to the $batch it travels as POST request over the web and thus it won't be cached.

like image 141
Vitek Karas MSFT Avatar answered Sep 24 '22 09:09

Vitek Karas MSFT


I defer to @Vitek's answer to the OP's question:

OData itself doesn't limit the length of the Url

But if others who arrive here because of IIS limitations : The request filtering module is configured to deny a request where the query string is too long., they may benefit from my answer. Follow that error's instructions:

Verify the configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString setting in the applicationhost.config or web.config file.

Follow the instructions:

<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxQueryString="50000">
        </requestLimits>
        ...

You may also get this error: The length of the query string for this request exceeds the configured maxQueryStringLength value.

This technique is described here and here, and it looks like this:

<configuration>
    <system.web>
        <httpRuntime maxQueryStringLength = "50000" ... />
like image 25
The Red Pea Avatar answered Sep 20 '22 09:09

The Red Pea