This documentation is archived and is not being maintained.

AJAX Service Without Configuration

Download sample

This sample demonstrates how to use Windows Communication Foundation (WCF) to create a basic ASP.NET Asynchronous JavaScript and XML (AJAX) service (a service that you can access by using JavaScript code from a Web browser client) without using any configuration settings. The service uses special syntax in the .svc file to automatically enable an AJAX endpoint.

AJAX support in WCF is optimized for use with ASP.NET AJAX through the ScriptManager control. For an example of using WCF with ASP.NET AJAX, see the AJAX Samples.

Bb472534.note(en-us,VS.90).gifNote:
This sample requires that .NET Framework version 3.5 is installed to build and run. Visual Studio 2008 is required to open the project and solution files.

Bb472534.note(en-us,VS.90).gifNote:
The setup procedure and build instructions for this sample are located at the end of this topic.

This sample builds upon the AJAX Service Using HTTP POST. However, note that the Web.config file does not contain any WCF configuration settings. Because all settings in the file pertain to ASP.NET, the file could be removed completely if ASP.NET were not used by ConfigFreeClientPage.aspx. Instead of using WCF configuration, the sample uses a special setting in the .svc file to automatically enable an AJAX endpoint without configuring it.

The Service.svc file contains the following code.

<%ServiceHost
    language=c#
    Debug="true"
    Service="Microsoft.Ajax.Samples.CalculatorService
    Factory=System.ServiceModel.Activation.WebScriptServiceHostFactory
%>

The WebScriptServiceHostFactory factory is the component that automatically configures an AJAX endpoint. The endpoint is configured at an empty address relative to the .svc file—this means that the address of the service is http://localhost/ServiceModelSamples/service.svc, with no additional suffixes other than the operation name. For example, to invoke the Add operation, you must make an HTTP POST request to http://localhost/ServiceModelSamples/service.svc/Add. The ASP.NET ScriptManager control in ConfigFreeClientPage.aspx sends that request. For more information about using the ScriptManager control, see the Basic AJAX Service sample.

To set up, build, and run the sample

  1. Ensure that you perform the setup instructions in One-Time Set Up Procedure for the Windows Communication Foundation Samples.

  2. Build the solution ConfigFreeAjaxService.sln as described in Building the Windows Communication Foundation Samples.

  3. Navigate to http://localhost/ServiceModelSamples/ConfigFreeClientPage.aspx (do not open ConfigFreeClientPage.aspx in the browser from within the project directory).

Bb472534.note(en-us,VS.90).gifNote:
When running this sample, please ensure that Anonymous Authentication and Windows Authentication are not enabled simultaneously for the ServiceModelSamples folder in IIS. If that is the case, please disable Windows Authentication. Once you have run the sample, enable Windows Authentication and run "iisreset".

See Also

Other Resources

Basic AJAX Service


© 2007 Microsoft Corporation. All rights reserved.
Show: