简体   繁体   中英

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.

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.

I have tried JQUERY but the parameter values that were sent to the server were blanks

    $(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?

Ah, I figured it out. I had to change the Location assignment to

var Location = {"Name": "ABC", "Address": "123"};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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