Reputation: 1676
I'm having a bit of an issue with accessing a C# webservice via JQuery. I have a WSDL and a .svc and I'm not entirely sure of how to access the functions I need. I've read: http://www.andrewrowland.com/article/display/consume-dot-net-web-service-with-jquery/ but it doesn't make any sense where I do not have .asmx pages in my application. I know this is a novice question but I'm truly stuck.
Upvotes: 1
Views: 608
Reputation: 7489
On the server end you can publish a service operation with either a [WebGet] or [WebInvoke] attribute,
[WebGet]
public string Get()
{
return "Hello, world!";
}
Keep in mind you will also need to use WebHttpBinding for the REST functionality, see this link for details: http://weblogs.asp.net/kiyoshi/archive/2008/10/08/wcf-using-webhttpbinding-for-rest-services.aspx
Then on the client side, you can use $.ajax or $.get to call the function,
$.get("http://localhost/somewcfservice.svc/Get", function (data) {
alert(data);
}
The first parameter is the URI of your service operation, and the second argument is a function you pass to the $.get method as a callback for once you receive the data.
The above code should produce an alert in the browser that says, "Hello, world!"
Go here for details: http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.aspx
Upvotes: 2
Reputation: 1038930
Here's an article you could go through. And forget about .asmx if you are using WCF. ASMX is legacy stuff that should no longer be used. As explained in the article you could expose your WCF service using a REST endpoint so that it is accessible through javascript.
And here's another guide.
Upvotes: 1