Odata batch "GET" with web methods

Jun 27, 2011 at 10:13 AM

Helllo codeplex community!

I have some issues with creating a batch-"GET" request with dajajs. The request should query a web-methods

Here's my code:

function LoadWaterChartData(currentHostname,latitude,longitude) {
    var ratingServiceUri = "http://" + currentHostname + "/RatingDataService.svc/$batch";
    var ratingRequestArray = new Array();
    var nowDate = new Date();
    var thisYear = nowDate.getFullYear();
    var radius = 10.0;

    for(var i = 10; i >= 0; i--)
    {
        ratingRequestArray.push({            
             requestUri: "UserRatings?latitude="+latitude+"&longitude="+longitude+"&ratingTaget='water'&radius=10&startTime=datetime'"+(thisYear-i)+"-01-01T00:01:00Z'&endTime=datetime'" + (thisYear-i) + "-12-31T23:59:00Z'",
             //requestUri: "UserRatings?filter=((Longitude sub " + longitude + ") lt " + radius + ") and ((latitude sub " + latitude + ") lt " + radius + ") and ( RatingTime gt datetime'" + (thisYear - i) + "-01-01T00:01:00Z') and (RatingTime lt datetime'" + (thisYear - i) + "-12-31T23:59:00Z') And (RatingTarget eq 'water')",
             method: "GET"
        });
    }

    OData.request({
        requestUri: ratingServiceUri,
        method: "POST",
        data: { __batchRequests: ratingRequestArray }
    },
    function (data, response) {

    },
    function (error) {

    }, OData.batchHandler);
}

When I execute the code, the error handler says following error-message: "Serialization of batches of type complex is not supported".

Did I made any mistake in the way of calling the dajajs-batching-function? Do you have any idea, how to call this webmethod via odata-batching?

Thanks a lot, if you could help me with my issues.

Regards,

Tino

Jun 29, 2011 at 2:16 AM

Hi Tino,

    Hope you are doing great.  I'm unable to repro the issue that you mention, could you please let us know which DataJS version, browser (and version) you are using?

Thanks

Alex Trigo. 

Jun 29, 2011 at 7:38 AM

Hi ATrigo,

thanks for your reply.

I use the datajs-0.0.3 version with the Internet Explorer 9. But I think it's not a browser issue.

When i looked at the code above this morning, i recognized, that i commented the wrong line.

So the correct requestUri from my issue is:

requestUri: "UserRatings?filter=((Longitude sub " + longitude + ") lt " + radius + ") and ((latitude sub " + latitude + ") lt " + radius + ") and ( RatingTime gt datetime'" + (thisYear - i) + "-01-01T00:01:00Z') and (RatingTime lt datetime'" + (thisYear - i) + "-12-31T23:59:00Z') And (RatingTarget eq 'water')"

I can't understand, why datajs/ODATA can't handle this request, because it's a normal ODATA filter request, that works fine if i run via browser.

But in the batch-request it doesn't work because of the described issue.

Do you maybe know a reason for this issue?

Thanks and regards,

Tino

Jun 29, 2011 at 8:37 PM

Hi Tino

I'm sorry, but I still can't repro the issue you describe using the sample code above. A couple of pointers... First, I would recommend using datajs.0.0.4 instead :).  Second, can you please use the function below and let me know what the alert message is:

function LoadWaterChartData(currentHostname,latitude,longitude) {
    var ratingServiceUri = "http://" + currentHostname + "/RatingDataService.svc/$batch";
    var ratingRequestArray = [];
    var nowDate = new Date();
    var thisYear = nowDate.getFullYear();
    var radius = 10.0;

    for(var i = 10; i >= 0; i--)
    {
        ratingRequestArray.push({          

             requestUri: "UserRatings?latitude="+latitude+"&longitude="+longitude+"&ratingTaget='water'&radius=10&startTime=datetime'"+(thisYear-i)+"-01-01T00:01:00Z'&endTime=datetime'" + (thisYear-i) + "-12-31T23:59:00Z'",
             //requestUri: "UserRatings?filter=((Longitude sub " + longitude + ") lt " + radius + ") and ((latitude sub " + latitude + ") lt " + radius + ") and ( RatingTime gt datetime'" + (thisYear - i) + "-01-01T00:01:00Z') and (RatingTime lt datetime'" + (thisYear - i) + "-12-31T23:59:00Z') And (RatingTarget eq 'water')",
             method: "GET"
        });
    }

    OData.request({
        requestUri: ratingServiceUri,
        method: "POST",
        data: { __batchRequests: ratingRequestArray }
    },
    function (data, response) {

    },
    function (error) {
	alert(window.JSON.stringify(error));
    }, OData.batchHandler);
}
Finally, can you please also run your code in the debugger using the non-minified datajs build and set a breakpoint in line 4019 if you use datajs.0.0.3 or line 4446 if datajs.0.0.4 is used and let me know what the value of the "type" variable is?
Regards,
Alex Trigo.