我有一个带参数的RESTFUL WCF服务PUT方法,我无法使用正确的参数值执行它。
OperationContract()
WebInvoke( Method:="PUT", UriTemplate:="/Fixit/{Id}")
Public Sub UpdateLocation(ByVal Id As String, ByVal location As Location)
End Sub
位置是一个类,它具有以下属性:
DataContract(Name:=MyLocation,Namespace="")
Public class Location
DataMember(Order:=1)
Public Property Name As String
DataMember(Order:=2)
Public Property Address As String
End Class
我尝试过使用WebRequest.create(uri)
和WebResponse
,但不确定如何传递位置类内容。
我已经尝试过JQUERY,但发送到服务器的参数值是空白
$(function () {
var Location = { "MyLocation": { "Name": "ABC", "Address": "123"} };
$.ajax({
type: "PUT",
url: "http://localhost/Fixit/{Id}",
data: JSON.stringify(Location),
contentType: "application/json;charset=utf-8",
processData:false,
dataType: "json",
success: function (data) {
alert("success");
},
error: function (data, status, jqXHR) {
alert("Failed: " + data.responseText);
}
});
});
如何使用此PUT方法,将数据传递给Location类?
答案 0 :(得分:0)
var Location = {“Name”:“ABC”,“Address”:“123”};