batch: server returns "The content type specified in not valid for batch requests. Content type must be 'multipart/mixed' and there must be a valid single boundary delimiter specified."

Dec 7, 2011 at 11:46 AM
Edited Dec 7, 2011 at 1:01 PM

I am trying use data.js with batch operations:

 

        var request = {};
        request.requestUri = this.get__batchUrl();
        request.method = 'POST';
        request.headers = {};

 

        var batchRequest = {};
        batchRequest.requestUri = this.get_serviceUrl();
        batchRequest.method = 'GET';
        var batchData = {};
        batchData.__batchRequests = [];
        batchData.__batchRequests.add(batchRequest);
        request.data = batchData;

 

then I call OData.request. Fidler shows following request: 

 

POST http://localhost/Service/EngineData.svc/$batch HTTP/1.1
DataServiceVersion: 1.0
Session-Id: sZ6PXiyhSGJN17I/c2d1jo8VbUWwodnNs961nUv7x3TjVyrqBrZU5Pin951ziP7LCIZjVjZn6pOJjrHEsWyMEpv9zV0pf5L0QHUDfckNJ+U=
Service-Name: Server
Accept: application/atomsvc+xml;q=0.8, application/json;q=0.5, */*;q=0.1
Content-Type: application/json

{"__batchRequests":[{"requestUri":"/Service/EngineData.svc/SubmitForm?folderId='dd'&actionName='FirstAction'&formName='dd'&serverData='dd'&fields=''","method":"GET"}]}

 

but server rerurns "The content type specified in not valid for batch requests. Content type must be 'multipart/mixed' and there must be a valid single boundary delimiter specified."

What can be wrong? I use WCF data service.

Dec 8, 2011 at 6:25 PM

Hi Slava,

   Hope you are doing great. Seems to me that the batch handler is not being used in the call to to OData.request thus causing the request to be sent as a regular POST request instead of a batched multipart request.  Please make sure that your call to OData.request looks like this:

OData.request(request, function (data, response) { //success callback }, function (err) { // error callback }, OData.batchHandler);
Regards,
Alex Trigo.
Dec 9, 2011 at 7:18 AM

Hi Alex,

Thank you, now it is working.

regards, Slava

Dec 9, 2011 at 7:20 AM

the problem was in OData.batchHandler, i skipped it