使用Breezjs调用saveChanges的问题

时间:2014-06-13 21:31:32

标签: asp.net-web-api odata breeze

我尝试使用sql后端轻松地使用我的webapi / odata服务来处理实体框架模型。

我已经让它从我的数据库中检索数据,当我执行createEntity()然后调用saveChanges()时遇到麻烦。

我已经像这样配置了我的批处理路线

 var cors = new EnableCorsAttribute("*", "*", "*");
        config.EnableCors(cors);

        // Web API routes
        config.Routes.MapHttpBatchRoute(
              routeName: "WebApiBatch",
              routeTemplate: "odata/$batch",
              batchHandler: new System.Web.Http.Batch.DefaultHttpBatchHandler(GlobalConfiguration.DefaultServer));

当我调用保存更改时,我收到http 500服务器错误,消息为:

Invalid 'HttpContent' instance provided. It does not have a content type header with a value of 'application/http; msgtype=request'.
Parameter name: content

发送到服务器的流是:

    POST http://gx9020-01:91/odata/$batch HTTP/1.1
Accept: multipart/mixed
DataServiceVersion: 2.0
Content-Type: multipart/mixed;boundary=batch_9245-db9a-4873
MaxDataServiceVersion: 3.0
Referer: http://localhost:61678/WebForm1.aspx
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Connection: Keep-Alive
Content-Length: 731
DNT: 1
Host: gx9020-01:91
Pragma: no-cache


--batch_9245-db9a-4873
Content-Type: multipart/mixed; boundary=changeset_0952-3d90-c3e2

--changeset_0952-3d90-c3e2
Content-Type: application/http
Content-Transfer-Encoding: binary

POST odata/MAP_Counterparty 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

{"MAP_CounterpartyID":-1,"SOURCE_SYSTEM":null,"TARGET_SYSTEM":null,"SOURCE_CODE":null,"TARGET_CODE":null,"TARGET_CODE2":null,"DRT_ID":null,"CREATE_DATETIME":null,"MODIFY_DATETIME":null,"Create_User":null,"Modify_User":null}
--changeset_0952-3d90-c3e2--

--batch_9245-db9a-4873--

如何让saveChanges()正常工作?

1 个答案:

答案 0 :(得分:2)

我发现了问题。我使用DefaultHttpBatchHandler而不是DefaultODataBatchHandler。