Web Services for Ajax

This topic describes how to access Web services from client script in AJAX-enabled ASP.NET Web pages. The services can be either custom services that you create, or built-in application services. The application services are provided as part of ASP.NET AJAX, and include authentication, roles, and profile services. 

Custom Web services can be in the form of .ASP.NET Web services (.asmx services), or Windows Communication Foundation (WCF) services (.svc services). 

This topic contains the following information:

·         Scenarios

·         Background

·         Examples

·         Additional Resources

·         Class Reference

·         What's New

Scenarios

You use WCF and ASP.NET in the following cases: 
  • If you have already created WCF services, you can add endpoints to enable script in AJAX-enabled Web pages to access the services. 
  • If you have already created ASP.NET Web (.asmx) services, you can modify them to enable script in AJAX-enabled Web pages to access the same service. 
  • If you want to create a custom Web service that will be accessed from ASP.NET AJAX Web pages, you can implement it as a WCF service or as an ASP.NET Web service (.asmx file). 
  • You can use the built-in ASP.NET application services to access users' authentication, roles, and profile information from client script that runs in an AJAX-enabled Web page.

Background 

ASP.NET enables you to create Web services can be accessed from client script in Web pages. The pages communicate with the server through a Web service communication layer that uses AJAX technology to make Web service calls. Data is exchanged asynchronously between client and server, typically in JSON format. 

Client-Server Communication for AJAX Clients 

In AJAX-enabled Web pages, the browser makes an initial request to the server for the page, and then makes subsequent asynchronous requests to Web services for data. The client communication elements are in the form of downloaded proxy classes from the server and the core client-script library. The server communication elements are handlers and custom services. The following illustration shows the elements that are involved in the communication between the client and the server.