2015-11-29 10 views
10

Ich habe eine ASP.NET 5-Anwendung, und ich möchte OData v4 damit verwenden. HierOData mit ASP.NET 5 registrieren

ist, was ich versucht habe:

1.Ich folgende nuget Pakete importiert:

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

2.Called dies in der Startup.Configure Methode

GlobalConfiguration.Configure(ConfigOData); 

3.Und schließlich Dies ist die OData-Konfiguration

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)); 
} 

Jetzt werden die OData-Aufrufe von der Routing-Konfiguration des MVC verarbeitet (höchstwahrscheinlich, weil ich OData nicht korrekt bei ASP.NET 5 registriert habe).

Kann mir bitte jemand helfen?

+0

Sind Sie bereit, RC2 zu verwenden? –

+1

Wenn es die Arbeit erledigt, ja. – Ayman

Antwort

6

Hier ist, wie wir es mit dem 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(); 
     } 
    } 
} 

Hier konfigurieren können, ist, wie Sie es selbst ausprobieren können. Sie werden the .NET Core SDK installed.

git clone [email protected]:bigfont/WebApi.git 

cd WebApi\vNext\src\Microsoft.AspNetCore.OData 
dotnet restore 

cd ..\..\samples\ODataSample.BigFont\ 
dotnet restore 
dotnet run 

Dies ist das Ergebnis bei http://localhost:5000/odata

Result

Verbindungen

+0

Wo ist "ISampleService" definiert? – CodeGrue

+0

Das BigFont-Beispiel scheint nicht mehr verfügbar zu sein. Weiß jemand, wo es ein funktionierendes OData ASP.NET Core-Beispiel gibt? – CodeGrue

+0

@CodeGrue Es ist hier https://github.com/bigfont/webapi –