How to: Configure WCF Services in ASP.NET AJAX
During WCF service calls, the JSON format is used to exchange data between client application and the service.
To configure WCF services to enable calls from client script
Open the application's Web.config file.
Set the aspNetCompatibilityEnabled of the serviceHostingEnvironment element to true, as shown in the following example:
Configure the messaging stack to be applied to the HTTP pipeline as shown in the following example:
<bindings> <webHttpBinding> <binding name="default"/> </webHttpBinding> </bindings>
Configure the behavior element for the endpoints and services by defining the endpointBehaviors and the serviceBehaviors that is contained by the behaviors element.
The behavior element for the endpointBehaviors element must be configured so that Web scripting is enabled. The behavior element for the serviceBehaviors element must be configured so that the service metadata is published for retrieval by using an HTTP GET request.
The following example shows how to configure the behavior and endPointBehavior elements.
<behaviors> <endpointBehaviors> <behavior name="webScriptEnablingBehavior"> <enableWebScript/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MyServiceTypeBehaviors"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors>
Configure an endpoint for the service element whose webHttpBinding and behavioConfiguration attribute values were defined in the previous steps.
The following example shows how to configure the service element.
<services> <service name="Samples.Aspnet.SimpleService" behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint address="" binding="webHttpBinding" bindingConfiguration="default" contract="Samples.Aspnet.ISimpleService" behaviorConfiguration="webScriptEnablingBehavior"/> </service> </services>