我有一个带有参数的 RESTFUL WCF 服务 PUT 方法,但我无法使用正确的参数值执行它。
OperationContract()
WebInvoke( Method:="PUT", UriTemplate:="/Fixit/{Id}")
Public Sub UpdateLocation(ByVal Id As String, ByVal location As Location)
End Sub
Location 是一个类,它具有以下属性:
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
不确定如何传入 Location 类内容。
我试过 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 类?