简体   繁体   English

使用参数调用Rest WCF服务PUT方法

[英]Call Rest WCF service PUT method with parameter

I have a RESTFUL WCF services PUT method with parameters and I have not been able to execute it with the proper parameter values. 我有一个带参数的RESTFUL WCF服务PUT方法,但无法使用正确的参数值执行它。

OperationContract()

WebInvoke( Method:="PUT", UriTemplate:="/Fixit/{Id}")

Public Sub UpdateLocation(ByVal Id As String, ByVal location As Location)
End Sub

Location is a class and it has theses properties: 位置是一个类,它具有以下属性:

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

I have tried using WebRequest.create(uri) and WebResponse but no sure how to pass in the Location class content. 我尝试使用WebRequest.create(uri)WebResponse但不确定如何传递Location类内容。

I have tried JQUERY but the parameter values that were sent to the server were blanks 我尝试了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);
            }
        });
    });

How do I consume this PUT method, passing data to the Location class? 我如何使用此PUT方法,将数据传递到Location类?

Ah, I figured it out. 啊,我知道了。 I had to change the Location assignment to 我不得不将“位置分配”更改为

var Location = {"Name": "ABC", "Address": "123"}; var Location = {“名称”:“ ABC”,“地址”:“ 123”};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM