我有一个WCF REST服务,它有两个简单的方法。发送JSON数据到WCF服务?
[OperationContract]
[WebInvoke(Method="GET",
ResponseFormat=WebMessageFormat.Json,
RequestFormat=WebMessageFormat.Json,
UriTemplate = "request/{controlType}")]
string GetJSONConfig(string controlType);
[OperationContract]
(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
UriTemplate = "save/{jsonString}")]
string SaveJSON(string jsonString);
第一种方法是从javascript代码中调用。但我在哪里发送JSON数据到第二个并获得404错误。
有人遇到这种类型的问题。
$(document).ready(function() {
var circle = function() {
this.x = 100;
this.y = 100;
this.r = 10;
};
var x = new circle();
var arr = [];
arr.push(x);
var jsonData = JSON.stringify(arr);
$('#serviceCall').click(function() {
$.ajax(
{
url: 'http://localhost:52506/JsonDataService.svc/save/',
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(arr),
processData: true,
success: function (data) {
document.getElementById("data").value = data;
},
error: function (data) {
document.getElementById("data").value = data;
}
});
});
});
这是javascript代码库。
您在第二种方法中缺少一些语法。 [WebInvoke准确。 – ZiNNED