ASP.NET Web API OData批处理返回HTTP 404

时间:2014-08-25 15:14:46

标签: cors asp.net-web-api2 asp.net-web-api-routing jaydata

我开始使用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(来自Fiddler)

回复

{"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.

问题是:为什么批量操作失败?

谢谢!

1 个答案:

答案 0 :(得分:0)

ASP.NET WebAPI OData不支持批处理操作,但您可以按照以下文章对其进行配置 - Introducing batch support in Web API and Web API OData