问题
I have been going through the tutorials at http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api to create an OData webservice.
I have my service set up as follows:
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Analytic>("Analytics");
var edmModel = modelBuilder.GetEdmModel();
config.Routes.MapODataRoute(
routeName: "Odata",
routePrefix: "odata",
model: edmModel);
I can issue a get request to http://localhost:49255/odata/Analytics
then the webservice functions as expected.
When I try and use the batch endpoint I am getting a 404. I am posting to
http://localhost:49255/odata/$batch
as seems to be indicated here. http://www.odata.org/documentation/odata-v2-documentation/batch-processing/
I found the following page https://aspnetwebstack.codeplex.com/wikipage?title=Web%20API%20Request%20Batching which suggests that I need to explicity be setting the BatchHandler
config.Routes.MapODataRoute(
routeName: "defaultOdata",
routePrefix: "odata",
model: GetModel(),
batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
But DefaultODataBatchHandler
doesn't seem to exist. In fact System.Web.Http.OData.Batch
doesn't seem to exist at all. I am using Microsoft.AspNet.WebApi.OData version 4.0.30506
.
I tried to update to the nightly build but this didn't work (don't know if anyone can tell me how I can get this working?)

Am I right in thinking that I just need to wait for a newer build to be released?
回答1:
Tom, you can try the following to see if it resolves your issue of upgrading to nightly builds:
Uninstall "Microsoft.AspNet.Mvc.FixedDisplayModes" package.
Upgrade the OData package using your command mentioned in the post.
When you launch the application, you would probably see the following error:
[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location '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'.
To fix the above error, modify the assembly binding in Web.config to below:
<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>
Your should be able to launch the application successfully now.
来源:https://stackoverflow.com/questions/17211914/how-to-create-where-the-batch-endpoint-is-for-an-asp-net-odata-webservice