本文介绍了如何在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
发布评论