如何在ASP.NET 5中注册OData

编程入门 行业动态 更新时间:2024-10-19 11:35:58
本文介绍了如何在ASP.NET 5中注册OData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个ASP.NET 5应用程序,我想与它一起使用OData v4.

I have an ASP.NET 5 application and I would like to use OData v4 with it.

这是我尝试过的:

1.我导入了以下nuget包:

1.I imported the following nuget packages:

"Microsoft.AspNet.WebApi": "5.2.3", "Microsoft.AspNet.OData": "5.7.0", "Microsoft.AspNet.Hosting": "1.0.0-rc1-final"

2.在Startup.Configure方法中调用此

GlobalConfiguration.Configure(ConfigOData);

3.最后是OData配置

3.And finally this is the OData configuration

private static void ConfigOData(HttpConfiguration config) { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); var EDM = builder.GetEdmModel(); //OData v4.0 config.MapODataServiceRoute("odata", "odata", EDM, new DefaultODataPathHandler(), conventions, new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer)); }

现在,MVC的路由配置正在处理OData调用(很可能是因为我没有在ASP.NET 5中正确注册OData).

Now the OData calls are being processed by the MVC's routing configuration (most probably because I did not register OData with ASP.NET 5 properly).

有人可以帮我吗?

推荐答案

以下是我们如何使用 ASP.NET Core RC2 OData.

namespace ODataSample { using Microsoft.AspNetCore.OData.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using ODataSample.Models; public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddOData<ISampleService>(); } public void Configure(IApplicationBuilder app) { app.UseOData("odata"); app.UseMvc(); } } }

这是您自己尝试的方法.您需要安装 .NET Core SDK.

Here is how you can try it yourself. You will need to have the .NET Core SDK installed.

git clone git@github:bigfont/WebApi.git cd WebApi\vNext\src\Microsoft.AspNetCore.OData dotnet restore cd ..\..\samples\ODataSample.BigFont\ dotnet restore dotnet run

这是localhost:5000/odata

链接

  • GitHub中的存储库.
  • GitHub中的ISampleService .
  • The repository in GitHub.
  • The ISampleService in GitHub.

更多推荐

如何在ASP.NET 5中注册OData

本文发布于:2023-11-14 04:22:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586204.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   ASP   OData   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!