【问题标题】:OData v4 Custom functions without namespace in WebAPI 2.2WebAPI 2.2 中没有命名空间的 OData v4 自定义函数
【发布时间】:2015-08-13 14:34:57
【问题描述】:

我们想在 WebAPI 2.2 上为我们的新项目使用 ODataV4,但有一个问题:url 设计。 我们必须通过我们的 api 传递 json 数据和二进制数据(图像)。

是否有可能避免 OData 路由上自定义函数的命名空间外观? /odata/Customers/GetByName('Name') 而不是 /odata/Customers/CustomerService.GetByName('Name')

以及如何使用 OData 控制器实现对二进制数据(jpeg 图像)的响应? 一种非常丑陋的方法是将 OdataControllers 和 ApiControllers 托管在一个项目中并使用不同的 url 区域。

/odata/Customers(1) -> OdataControllers /api/Customers/1/ProfileImage -> ApiController

【问题讨论】:

    标签: asp.net-web-api odata asp.net-web-api2


    【解决方案1】:

    【讨论】:

    • 谢谢。看起来不错。但我总是得到回复{ "error":{ "code":"","message":"No HTTP resource was found that matches the request URI 'http://testapp.localhost/v1/Parts(432)/Rate'.","innererror":{ "message":"No routing convention was found to select an action for the OData path with template '~/entityset/key/unresolved'.","type":"","stacktrace":"" } } }
    • 好的。我已将 public async Task<HttpResponseMessage> Rate([FromODataUri] long key) 更改为 public async Task<HttpResponseMessage> Rate() 然后它工作。但是如何引用 Parts Key 呢?
    【解决方案2】:

    谢谢你,千里!你真的帮了大忙!

    HttpConfiguration config = …
    config.EnableCaseInsensitive(caseInsensitive: true);
    config.EnableUnqualifiedNameCall(unqualifiedNameCall: true);
    config.EnableEnumPrefixFree(enumPrefixFree: true);
    config.MapODataServiceRoute("odata", "odata", edmModel);
    

    【讨论】:

      猜你喜欢
      • 2014-10-05
      • 2015-05-31
      • 2019-04-08
      • 1970-01-01
      • 2015-11-06
      • 2015-03-07
      • 1970-01-01
      • 2023-03-17
      • 2014-10-08
      相关资源
      最近更新 更多