Webapi: [feature/netcore] $batch endpoint returns 404 error

Created on 4 May 2018  路  2Comments  路  Source: OData/WebApi

After adding the DefaultODataBatchHandler I am still unable to issue batch requests.
Every call to the endpoint /odata/$batch results in a 404 - Not Found error.

Assemblies affected

OData WebApi .Net Core Nightly (7.0.0-Nightly201805031241)

Reproduce steps

  • copy the AspNetCore Sample App or use any existing OData .Net Core app

  • change the OData Route Mapping to use the DefaultODataBatchHandler:

app.UseMvc(builder => builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel(), new DefaultODataBatchHandler()));

  • call the /odata/$batch endpoint with a POST call:
POST /odata/$batch HTTP/1.1
Host: localhost:5913
Connection: keep-alive
Content-Length: 217
Pragma: no-cache
Cache-Control: no-cache
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
Content-Type: multipart/mixed; boundary=batch_abbe2e6f-e45b-4458-9555-5fc70e3aebe0
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7

--batch_abbe2e6f-e45b-4458-9555-5fc70e3aebe0
Content-Type: application/http
Content-Transfer-Encoding: binary

GET /odata/Movies HTTP/1.1
Accept: application/json

--batch_abbe2e6f-e45b-4458-9555-5fc70e3aebe0--

Expected result

The OData batch request is processed and a valid response is returned

Actual result

The endpoint returns a 404 - Not Found error

Additional Information

Sample repo https://github.com/marcuskrahl/AspNetCoreODataBatchSample

I also temporariliy added my own extension of DefaultODataBatchHandler to see if any of its methods are called. However only the constructor is called.

featurnetcore question

Most helpful comment

@marcuskrahl

Please add UseODataBatching() before UseMvc:

```C#
app.UseODataBatching();
app.UseMvc(builder => builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel(), new DefaultODataBatchHandler()));


I tested using your repo. It can work and give me the result as below:

```json
--batchresponse_906af1b6-e226-4800-8ec0-c0bff3b3f569
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal; odata.streaming=true; charset=utf-8
OData-Version: 4.0

{"@odata.context":"http://localhost:5913/odata/$metadata#Movies","value":[{"ID":1,"Title":"Conan","ReleaseDate":"2017-03-03T00:00:00-08:00","Genre":"Comedy","Price":1.99}]}
--batchresponse_906af1b6-e226-4800-8ec0-c0bff3b3f569--

All 2 comments

@marcuskrahl

Please add UseODataBatching() before UseMvc:

```C#
app.UseODataBatching();
app.UseMvc(builder => builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel(), new DefaultODataBatchHandler()));


I tested using your repo. It can work and give me the result as below:

```json
--batchresponse_906af1b6-e226-4800-8ec0-c0bff3b3f569
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal; odata.streaming=true; charset=utf-8
OData-Version: 4.0

{"@odata.context":"http://localhost:5913/odata/$metadata#Movies","value":[{"ID":1,"Title":"Conan","ReleaseDate":"2017-03-03T00:00:00-08:00","Genre":"Comedy","Price":1.99}]}
--batchresponse_906af1b6-e226-4800-8ec0-c0bff3b3f569--

Adding app.UseODataBatching() does indeed work. I am going to close this issue because everything is working as expected afterwards, but it might be helpful to add this information to the official documentation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TehWardy picture TehWardy  路  5Comments

suadev picture suadev  路  3Comments

VikingsFan picture VikingsFan  路  5Comments

abkmr picture abkmr  路  3Comments

rleos picture rleos  路  5Comments