I have created the following JSON WCF Service that accepts a .NET System.DateTime
value as an input parameter:
[OperationContract]
[WebGet(ResponseFormat=WebMessageFormat.Json)]
ReclaimedH2OMetric GetCurrentReclaimedH2OMetric(System.DateTime currentDate);
When I try to consume the service using jQuery
in my web page I get the following error:
The server encountered an error processing the request. The exception message is 'SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.'
Here is my jQuery code:
var rawResults;
var currentDate = new Date('10/1/2012');
var jsonDate = '\\/Date(' + currentDate.getTime() + ')\\/';
$.ajax(
{
async: false,
type: "GET",
contentType: "application/json; charset=utf-8",
url: "http://www.mydomain.com/Dashboard_WaterResources/WCFService/Dashboard.svc/GetCurrentReclaimedH2OMetric",
dataType: "json",
data: '{"currentDate": "' + jsonDate + '"}',
success: function (results) {
rawResults = results;
},
error: function (xhr) {
alert(xhr.responseText);
}
});
The following line of code var jsonDate = '\\/Date(' + currentDate.getTime() + ')\\/';
was trying to format the date in the proper JSON format using this question as a reference