Sending JSON to WCF Rest Service - object is always null

后端 未结 1 1407
长发绾君心
长发绾君心 2020-12-16 14:17

I am trying to get my application working by using REST, WCF and JSON (new to all those technologies). I have the \'GET\' working fine. It is the \'POST\' that is causing

相关标签:
1条回答
  • 2020-12-16 14:42

    If Wrapped is what you want to do, then you need to wrap the request in the operation parameter name:

    var input = { "ContactCompanyObject" : newCustomer };
    $.ajax({
       data: input
       ...
    });
    

    Or for the second example, if you change the ajax call to the one shown below, you should get the expected result:

    var input = { NullTestTypeObject: { NullTestString: "Hello", NullTestInt: 123} };
    alert("Input: " + JSON.stringify(input));
    $.ajax({
        type: "POST",
        url: "./Service1.svc/nulltestaddress/NullTestPost",
        contentType: "application/json",
        data: JSON.stringify(input),
        success: function (result) {
            alert("POST result: " + JSON.stringify(result));
        }
    });
    
    0 讨论(0)
提交回复
热议问题