简体   繁体   English

Web API 2.2和OData V4路由约定

[英]Web API 2.2 and OData V4 Route Conventions

I upgraded to OData V4 and I realised the routing conventions have changed. 我升级到OData V4,并且意识到路由约定已更改。 So instead of 所以代替

http://somesite.com/api/products/1

You would have the following 您将拥有以下内容

http://somesite.com/api/products(1)

Now this is fine for new apps going forward, but we need to support the traditional url's for legacy apps. 现在,这对于以后的新应用程序来说很好,但是我们需要为旧版应用程序支持传统的url。 Is there a way to support both url's, or the traditional url for the time being? 有没有办法同时支持这两个url或传统url?

If I have the following example 如果我有以下示例

[ODataRoute("{key}")]
public async Task<IHttpActionResult> Put([FromODataUri] string key, Dealer dealer)
{
    // some logic code here        
}

I get the following error 我收到以下错误

The path template '{key}' on the action 'Put' in controller 'Dealers' is not a valid OData path template. Resource not found for the segment '{key}'

If you are switching to OData v4 from an earlier version, there are several breaking changes.. ie for example, v3 clients will not be able to consume the response returned by a v4 service... Hence uri may be the least of your problems.. 如果您要从较早版本切换到OData v4 ,可能会有一些重大更改。例如,v3客户端将无法使用v4服务返回的响应...因此,uri可能是最少的问题..

If you need to support existing clients.. then your only option would be to host two versions of the same service. 如果您需要支持现有的客户端,那么您唯一的选择是托管同一服务的两个版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM