1
votes

I try to implement Breeze together with a WebAPI OData WebService.

On the server side I use ODataConventionModelBuilder and DefaultODataBatchHandler:

var builder = new ODataConventionModelBuilder();
builder.EntitySet<MyModelType>("MyModelTypes");
builder.Namespace = typeof(MyModelType).Namespace;

config.Routes.MapODataRoute(
    routeName: "ODataRoute",
    routePrefix: "api",
    model: builder.GetEdmModel(),
    batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));

On the client side I use webApiOData:

breeze.config.initializeAdapterInstance('dataService', 'webApiOData', true);

Service name is /api, and I use server side metadata:

var dataService = 
    new breeze.DataService({
        serviceName: '/api', 
        hasServerMetadata: true  
    });
var manager = new breeze.EntityManager({
        dataService: dataService
    });

If I try now to call entityManager.saveChanges() it correctly calls /api/$batch. But the changeset itself tries a POST to /api/MyModelTypes:

--batch_389a-6d15-37bd
Content-Type: multipart/mixed; boundary=changeset_a807-ab31-a36a

--changeset_a807-ab31-a36a
Content-Type: application/http
Content-Transfer-Encoding: binary

POST api/MyModelTypes HTTP/1.1
Content-ID: 1
DataServiceVersion: 2.0
Accept: application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
Content-Type: application/json
MaxDataServiceVersion: 3.0

{"Id":-1,"Text":"Foo"}
--changeset_a807-ab31-a36a--

--batch_389a-6d15-37bd--

This results for the changeset in a call to http://myhost/api/api/MyModelTypes instead of http://myhost/api/MyModelTypes:

--batchresponse_4d3988b4-10e6-4df4-bae3-a1fa034a065c
Content-Type: multipart/mixed; boundary=changesetresponse_b1df8cf5-8450-43f7-9eda-    5dc6bfdb7554

--changesetresponse_b1df8cf5-8450-43f7-9eda-5dc6bfdb7554
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 404 Not Found
Content-ID: 1
Content-Type: application/json; charset=utf-8

{"Message":"No HTTP resource was found that matches the request URI 'http://myhost/api/api/MyModelTypes'."}
--changesetresponse_b1df8cf5-8450-43f7-9eda-5dc6bfdb7554--
--batchresponse_4d3988b4-10e6-4df4-bae3-a1fa034a065c--

What do I need to change to create Breeze the correct links in a batch request?

1

1 Answers

1
votes

It seems like this error was introduced sometimes between version 5.2.2 and 5.3.1 in the Microsoft.AspNet.WebApi.OData and BreezeJS is not adopted yet accordingly:

Can't save the data to OData controller after updating to Microsoft.AspNet.WebApi.OData 5.3.x

I've added an issue for BreezeJS: https://github.com/Breeze/breeze.js/issues/42