如何创建/批处理端点用于asp.net OData Web服务的位置

时间:2013-06-20 10:59:33

标签: asp.net-web-api odata

我一直在阅读教程 http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api 创建OData Web服务。

我的服务设置如下:

var modelBuilder = new ODataConventionModelBuilder();

modelBuilder.EntitySet<Analytic>("Analytics");

var edmModel = modelBuilder.GetEdmModel();

config.Routes.MapODataRoute(
   routeName: "Odata",
   routePrefix: "odata",
   model: edmModel);

我可以向http://localhost:49255/odata/Analytics发出get请求,然后webservice按预期运行。

当我尝试使用批处理终端时,我得到的是404.我发布到

http://localhost:49255/odata/$batch

似乎在这里表明。 http://www.odata.org/documentation/odata-v2-documentation/batch-processing/

我发现以下页面https://aspnetwebstack.codeplex.com/wikipage?title=Web%20API%20Request%20Batching表明我需要明确设置BatchHandler

config.Routes.MapODataRoute(
                routeName: "defaultOdata",
                routePrefix: "odata",
                model: GetModel(),
                batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));

DefaultODataBatchHandler似乎不存在。实际上System.Web.Http.OData.Batch似乎根本不存在。我正在使用Microsoft.AspNet.WebApi.OData version 4.0.30506

我尝试更新到每晚构建,但这不起作用(不知道是否有人可以告诉我如何让这个工作?)

nu-get error message

我是否正确地认为我只需要等待更新的版本发布?

1 个答案:

答案 0 :(得分:2)

Tom,您可以尝试以下操作,看看它是否解决了升级到夜间版本的问题:

  • 卸载&#34; Microsoft.AspNet.Mvc.FixedDisplayModes&#34;封装

  • 使用帖子中提到的命令升级OData包。

  • 启动应用程序时,您可能会看到以下错误:

    [A] System.Web.WebPages.Razor.Configuration.HostSection无法强制转换为[B] System.Web.WebPages.Razor.Configuration.HostSection。类型A源自&#39; System.Web.WebPages.Razor,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35&#39;在上下文中&#39;默认&#39;在位置&#39; C:\ windows \ Microsoft.Net \ assembly \ GAC_MSIL \ System.Web.WebPages.Razor \ v4.0_2.0.0.0__31bf3856ad364e35 \ System.Web.WebPages.Razor.dll&#39;。类型B源自&#39; System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35&#39;在上下文中&#39;默认&#39;位置&#39; C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET Files \ root \ cae46085 \ 829a2d25 \ assembly \ dl3 \ f12eaaeb \ d73d086c_ca6dce01 \ System.Web.WebPages.Razor.dll& #39;

  • 要修复上述错误,请将Web.config中的程序集绑定修改为以下内容:
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:bcl="urn:schemas-microsoft-com:bcl"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" /> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" /> </dependentAssembly> </assemblyBinding>

  • 您现在应该可以成功启动应用程序。