asp.net-web-api2asp.net-web-api-routingjaydata

ASP.NET Web API OData batch returning HTTP 404


I'm getting started with ASP.NET Web API v2 and OData (v3).
I've got a client made with JayData v 1.3.6

Client Context

onlinedb = new $todo.Types.ToDoContext({
    name: 'oData',
    oDataServiceHost: 'http://localhost:49375/odata'
});

Server Routes

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

Request
OPTIONS /odata/$batch HTTP/1.1 (From Fiddler)

Response

{"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'"}

Comments

http://localhost:49375/odata/Todo (GET operation) is working fine.

The question is: Why is batch operation failing?

Thanks!


Solution

  • Batch operations aren't supported by ASP.NET WebAPI OData, but you can configure it by following this article - Introducing batch support in Web API and Web API OData