Consuming a WCF service from an ASP.NET AJAX client
Nowadays, more and more web application development platforms have adopted AJAX features so as to provide rich client-side interaction and user experience in browser-based applications. ASP.NET AJAX is one of the representatives of the AJAX-enabled web application development platform. One cool feature of ASP.NET AJAX is that it can use script code to invoke XML Web Services within the hosting web application. As a unified service development platform, WCF also provides support for building services that can be consumed by an ASP.NET AJAX client.
In this recipe, we will demonstrate how to build an ASP.NET AJAX-enabled WCF service and consume it from an ASP.NET web page.
How to do it...
In the sample case, we will build both a WCF service and an ASP.NET web page, and host them in the same web application:
Create an AJAX-enabled WCF service.
Let’s create the WCF service first. The sample WCF service has a simple
ServiceContract
that contains...