I am using an ODataController to get my results for my queries. The Controller is defind as so:
public class RunController : ODataController
{
[EnableQuery(MaxNodeCount = 1000)]
public IHttpActionResult Get() {
...
}
}
If i go directly to the controller it works. My routes are set up so that i would go to this URL:
http://localhost:58704/odata/Run
Route configuration looks like the following:
config.MapODataServiceRoute(
routeName: "defaultOdata",
routePrefix: "odata",
model: GetModel(),
batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
Where the GetModel() looks like this:
public static Microsoft.OData.Edm.IEdmModel GetModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<RunController.RunModel>("Run");
return builder.GetEdmModel();
}
As you can see I have enabled a defaultOdataBatchHandler. The
http://localhost:58704/odata/$batch
Works without a hitch. Next step is to create the batch statement, which is done by datajs and looks like the following:
return OData.request({
requestUri: "http://localhost:58704/odata/$batch",
method: "POST",
data: {
__batchRequests: [
{requestUri: "Run", method: "GET" }
]
}
}, function (data, response) {
console.log(data.__batchResponses);
}, undefined, OData.batchHandler);
The batch query gets what it needs, and returns a HTTP 200. Which is awesome. The query inside which translates to http://localhost:58704/odata/Run
, returns a HTTP 404. And i cannot for the life of me understand why.
The line that says console.log(data.__batchResponses)
returns 1 object that has a message property saying; "HTTP request failed", and in the response the body says:
"{"message":"No HTTP resource was found that matches the request URI 'http://localhost:58704/odata/Run'.","messageDetail":"No type was found that matches the controller named 'odata'."}"
If i use the url that is displayed in the error message, it works without a hitch. Could it be that the method: "GET"
in the batch request is not working properly?