我知道有很多關於通過JQuery/JSON使用WCF REST的帖子,但是我無法讓它工作。我目前卡在日期參數。下面是我的C#方法:發送JQuery JSON到WCF REST使用日期
[OperationContract]
[WebInvoke]
[TransactionFlow(TransactionFlowOption.Allowed)]
string GoodRegister(DateTime pDtTimeStampTransac, Int32 pIDResource, Decimal pQty, enQtyLogType pQtyGoodLogType);
下面是我的JavaScript代碼:
/// <reference path="../Scripts/jquery-1.4.1-vsdoc.js" />
/// <reference path="json.js" />
Date.prototype.toMSJSON = function() {
var date = '\\\/Date(' + this.getTime() + ')\\\/';
return date;
};
function botaoclick() {
var date = new Date().toMSJSON();
var datavar = {
'pDtTimeStampTransac': date,
'pIDResource': 1,
'pQty': 1
};
$.ajax(
{
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://desk01:9876/ShopFloorService/script/GoodRegister",
dataType: "json",
data: JSON.stringify(datavar),
//data: '{"pDtTimeStampTransac":date, "pIDResource":"teste", "pQty":"3"}',
error: jqueryError,
success: function (msg) {
alert("back");
var divForResult = document.getElementById("test");
divForResult.innerHTML = "Result: <b>" + msg.d + "</b>";
}
}
)
}
function jqueryError(request, status, error) {
alert(request.responseText + " " + status + " " + error);
}
我的第一個問題是,我不斷收到日期序列化錯誤:
{"ExceptionDetail":{"HelpLink":null,"InnerException":{"HelpLink":null,"InnerException":{"HelpLink":null,"InnerException":null,"Message":"DateTime content '\\\/Date(1292616078638)\\\/' does not start with '\\\/Date(' and end with ')\\\/' as required for JSON.","StackTrace":" at System.Runtime.Serialization.Json.JsonReaderDelegator.ParseJsonDate(String originalDateTimeValue)\u000d\u000a at
它說,它不開始/結束它的開始和結束的方式。
我的第二個問題是:我是否必須騎上枚舉器,還是有辦法發送它?
哦,它幫助沒事。謝謝! – 2012-06-26 17:55:13
匿名用戶建議將this.getUTCOffset()添加到原型代碼 – mplungjan 2012-07-13 10:08:43