I created simple WCF service and added it to ASP.NET MVC application.
The service have a single method RepeatString:
[OperationContract]
public string RepeatString(string s, int times)
{
string result = "";
for (int i = 0; i < times; ++i)
{
result += s;
}
return result;
}
I tried to call this method from a view (.cshtml) using post and get methods:
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');
}
but neither has succeed.
Is there anything I should change in WCF service operation decoration or am I using jQuery.get/post wrongly?
/AjaxService1.svc/RepeatStringrather than~/AjaxService1.svc/RepeatStringin clientside, i.e. js code.