Export (0) Print
Expand All

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.

Bb472534.note(en-us,VS.100).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. As described in the Basic AJAX Service sample, WebScriptServiceHostFactory is used to host the service.

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

WebScriptServiceHostFactory automatically adds a WebScriptEndpoint to the service. If no configuration changes need to be made to the endpoint, the <system.ServiceModel> section can be completely removed from the Web.config file for the service. The Web.config file contains some ASP.NET settings, which are used by ConfigFreeClientPage.aspx. If that were not the case, the entire Web.config file could be removed.

Bb472534.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WCF\Basic\Ajax\ConfigFreeAjaxService

To set up, build, and run the sample

  1. Ensure that you perform the setup instructions in One-Time Setup 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.100).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

Community Additions

ADD
Show:
© 2014 Microsoft