Creating WCF Services for ASP.NET AJAX
Most Windows Communication Foundation (WCF) services may be exposed as a service compatible with ASP.NET AJAX by adding an appropriate ASP.NET AJAX endpoint.
If you are using Visual Studio, you may use a pre-built template for AJAX-enabled WCF services, available in the Add New Item dialog when working with ASP.NET Web Sites or Web Applications.
If you are not using the Visual Studio templates, there are two ways to create an ASP.NET AJAX endpoint:
Create the endpoint using dynamic host activation without using any configuration. This is the most basic approach if you are unfamiliar with the WCF configuration system. For more information, see How to: Add an ASP.NET AJAX Endpoint Without Using Configuration.
Add an AJAX-enabled endpoint to a WCF service using configuration. For more information, see How to: Use Configuration to Add an ASP.NET AJAX Endpoint.
The Web Programming Model described in the WCF REST Programming Model Overview may be used with ASP.NET AJAX services. Specifically:
You can use the WebGetAttribute and WebInvokeAttribute attributes to select between HTTP GET and HTTP POST verbs. If used correctly, this may significantly improve your application’s performance. For more information, see How to: Choose between HTTP POST and HTTP GET requests for ASP.NET AJAX Endpoints.
No other properties on the WebGetAttribute and WebInvokeAttribute attributes can be changed if compatibility with ASP.NET AJAX is required. Other aspects of the Web Programming Model can be used as long as the ASP.NET AJAX calling conventions are not violated.
More advanced scenarios require some additional details of AJAX support in WCF be understood:
To take advantage of ASP.NET features, for example, URL-based authentication and accessing the ASP.NET session information, you may want to enable the ASP.NET Compatibility Mode through configuration.
AJAX endpoints in WCF may even be consumed without the ASP.NET AJAX framework. Doing so requires an understanding of the support architecture of AJAX support in WCF. For a discussion of this architecture, see WCF REST Programming Object Model. For a code sample demonstrating this approach, see the AJAX Service with JSON and XML Sample.