大家好,我是 JSON 和 WCF 服务的新手。我正在尝试使用 JSON 调用 wcf 服务,而我的参数是我的数据合同类之一。
这是我的数据合同类。
namespace Employee.Services.DataContracts
{
using System;
using System.Runtime.Serialization;
[DataContract]
public class ReqDataContract
{
[DataMember]
public long Type { get; set; }
[DataMember]
public string ID { get; set; }
[DataMember]
public DateTime? FDate { get; set; }
[DataMember]
public long? UserID { get; set; }
}
}
这是 myWCF 服务功能
public void SaveRequ(ReqDataContract request)
{
var req=request;
}
这是接口实现
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
[return: MessageParameter(Name = "ReqData")]
void SaveRequ(ReqDataContract request);
.js 文件(AJAX 调用)
var selection = "{ \"Type\": 55,\"ID\":'test@yahoo.com' ,\"FDate\":" + null + " ,\"UserID\": 'ASDAS'}";
searchData = searchData + (searchData != '' ? "," : "") + selection;
if (searchData != null) {
searchData = "[" + searchData + "]";
}
var searchJSON = jQuery.toJSON(eval("(" + searchData + ")"));
var strJSON = searchJSON.toString();
params = '{\"request\":' + strJSON + '}';
$.ajax({
async: false, //To perform synchronize operation to get status
type: "POST",
url: servicePath + "SaveRequ",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: params,
processData: true,
success: function (data) {
// alert(data.ReqData);
},
error: function (xhr, result, id) { alert(xhr.responseText); }
});
一切正常,但问题是我在请求参数中获取所有值 null ......我错过了什么吗?请帮助我。