1
$ .ajax(..)JSONを使用してカスタムクラス/オブジェクトの 'ref引数'を持つasmx webmethodsを呼び出す方法はありますか?出来ますか?
私のC#コード -
public class MyCustomClass{ public int MyProperty; MyCustomClass(){}}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Method1(ref MyCustomClass MyCustomObj)
{ MyCustomObj.MyProperty*=2; return MyCustomObj;}
私のjs/jqueryのコード -
function myCustomClass(){this.myProperty;}
var myCustomObj = new myCustomClass();
myCustomObj.myProperty = 100;
$.ajax({
type: "POST",
data: "{'myCustomObj': " + JSON.stringify(myCustomObj) + "}",
url: "test.asmx/Method1",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
var data = response.d;
alert(data.MyProperty);
},
failure: function(msg) {
alert(msg);
}
});
このWebMethod属性の引数は参照によってされていない場合は、すべてが正常に動作します。 WebMethod属性の上記署名付き 、即ちREF引数によってで、私は(firebubを使用して見サーバ応答において)サーバーエラーを取得 -
No parameterless constructor defined...
Thx Darin。私はそれを試して、あなたが言及したように動作します。ちょうどそれを期待して – tubelight
@ tubelight、何が動作しないのですか?私がテストしたところ、正常に動作しました。私は 'response.d.MyProperty'で更新された値を得ることができました。 –
Thx Darin。私はそれを試して、あなたが言及したように動作します。私が見逃しているものがあることを念頭に置いて、気をつけていれば、それはref argで動作します。 – tubelight