我正在开始使用ASP。. NET Web API v2和OData (v3)。
我有一个客户端与JayData v 1.3.6
onlinedb = new $todo.Types.ToDoContext({
name: 'oData',
oDataServiceHost: 'http://localhost:49375/odata'
});
服务器线路
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.ContainerName = "WebAPIDataCollectorContext";
builder.EntitySet<TodoItem>("Todo");
config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.EnableCors();
}
请求
OPTIONS/odata/$batch HTTP/1.1
响应
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:49375/odata/$batch'.","MessageDetail":"No route providing a controller name was found to match request URI 'http://localhost:49375/odata/$batch'"}
评论
http://localhost:49375/odata/Todo (GET operation) is working fine.
问题是:为什么批处理操作失败?
谢谢!
ASP不支持批处理操作。. NET WebAPI OData,但您可以按照本文进行配置——在WebAPI和WebAPI OData中引入批处理支持