Calling WCF services from JavaScript

To consume the WCF service methods from JavaScript, we need to expose them as the RESTful service methods that accept and return the data in either JSON or XML formats. This helps developers to consume the WCF services as easily as the REST services, and use them with the jQuery $.ajax or $.getJSON (shorthand method of $.ajax) methods. To expose a WCF service as a REST service, we need to annotate the WCF service methods with the WebGet or WebInvoke attributes. The WebGet attribute is mostly used when making any HTTP GET request, whereas WebInvoke is used for all HTTP request methods.

The following code shows the representation of using the WebGet attribute on a WCF operation contract that returns the product ...

Get JavaScript for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.