簡単な WCF サービスを作成し、ASP.NET MVC アプリケーションに追加しました。
サービスには単一のメソッド RepeatString があります。
[OperationContract]
public string RepeatString(string s, int times)
{
string result = "";
for (int i = 0; i < times; ++i)
{
result += s;
}
return result;
}
post メソッドと get メソッドを使用して、ビュー (.cshtml) からこのメソッドを呼び出そうとしました。
function callAjaxService1() {
$.post("~/AjaxService1.svc/RepeatString", {s : 'Test', times : 12},
function(data) {
alert('data from service');
}, 'json');
}
function callAjaxService1() {
$.get("~/AjaxService1.svc/RepeatString", {s : 'Test', times : 12},
function(data) {
alert('data from service');
}, 'json');
}
しかし、どちらも成功していません。
WCF サービス操作の装飾で変更する必要があるものはありますか、それとも jQuery.get/post を間違って使用していますか?