0

次のような文字列を WCF サービスに渡しても問題ありませんか。

self.savePreferences = function(callback) {
        $.ajax({
            url: "services/Foo.svc/SavePreferences",
            type: 'POST',
            timeout: 3000,
            data: ko.mapping.toJSON(self.user().preferences),
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                if (result) {
                    alert("data saved " + result);
                } else {
                    //todo, send server email alert
                    alert("Something went wrong. We will look into it.");
                }
            }
        });
    }

この場合、サービスの jsonPreferences に対して常に null を取得します

 [OperationContract]
    [WebInvoke(
      Method = "POST", 
      RequestFormat = WebMessageFormat.Json)]
    string SavePreferences(string jsonPreferences);

または、これを行う必要がありますか:

データ: JSON.stringify(ko.mapping.toJSON(self.user().preferences))

4

0 に答える 0