OData Url Length Limitations

时光毁灭记忆、已成空白 提交于 2019-12-18 05:42:22

问题


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


回答1:


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.




回答2:


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" ... />



回答3:


I didn't find how the $batch is used. so I used $filter for sending a long request. Its pretty easy:

DataServiceQuery<CLIENT> ordersQuery = DataServiceQuery<CLIENT>)this.context.CLIENTS.AddQueryOption("$filter", MyFilter());

where MyFilter() return a string like this: "ID_CLIENT = 1 or ID_CLIENT = 2"

NB: Dont use the uppercase AND. it leads to and error. use and not AND



来源:https://stackoverflow.com/questions/4247985/odata-url-length-limitations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!