我使用WCF休息服务与POST方法如下发送JSON到WCF REST服务 - 对象的Fileds是空的
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/SampleMethod")]
int SampleMethod(SampleObject sampleObject);
,并呼吁从Javascript如下这项服务,
$.ajax({
type: 'POST',
url: 'http://localhost/SampleService/SampleService.svc/SampleMethod',
data: object,
contentType: "application/json; charset=utf-8",
dataType: "json",
processdata: true,
success: successCallback, //On Successfull service call
error: serviceFailed// When Service call fails
});
凡对象是在格式
的strigified JSON { “sampleObject”:{ “ID”:1, “名称”: “ABC”, “数据”: “样品数据”}}
上面我尝试使用的示例,但在服务端的所有对象字段(ID,名称,数据)为空。我没有得到这个问题。
当我写了这样的代码,我从来没有指定'BodyStyle',它的工作原理。你尝试过吗?否则,我不得不看'SampleObject'进一步调查。 – madd0 2012-04-03 11:25:50
您是否也可以添加您的端点配置? – 2012-04-03 19:36:29