AJAX Service Without Configuration
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.
Note
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.
Note
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 https://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 https://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
Ensure that you perform the setup instructions in One-Time Set Up Procedure for the Windows Communication Foundation Samples.
Build the solution ConfigFreeAjaxService.sln as described in Building the Windows Communication Foundation Samples.
Navigate to https://localhost/ServiceModelSamples/ConfigFreeClientPage.aspx (do not open ConfigFreeClientPage.aspx in the browser from within the project directory).
Note
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
© 2007 Microsoft Corporation. All rights reserved.