【发布时间】:2014-12-20 03:30:54
【问题描述】:
我尝试将 Breeze 与 WebAPI OData WebService 一起实现。
在服务器端我使用ODataConventionModelBuilder 和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));
在客户端我使用webApiOData:
breeze.config.initializeAdapterInstance('dataService', 'webApiOData', true);
服务名称是/api,我使用服务器端元数据:
var dataService =
new breeze.DataService({
serviceName: '/api',
hasServerMetadata: true
});
var manager = new breeze.EntityManager({
dataService: dataService
});
如果我现在尝试调用entityManager.saveChanges(),它会正确调用/api/$batch。但变更集本身会尝试向/api/MyModelTypes 发送 POST:
--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--
这导致更改集调用http://myhost/api/api/MyModelTypes 而不是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--
我需要更改哪些内容才能在批处理请求中创建 Breeze 正确链接?
【问题讨论】:
标签: asp.net-web-api odata breeze