Making a WCF Service Accessible from Client Script
To make a WCF service available from client script, it must satisfy the following requirements:
· The service must be hosted by a Web application that contains a file that has a .svc extension. This file contains an @ ServiceHost directive that points to the WCF service. The following example shows a @ ServiceHost directive.
· You must configure the Web application to support calling Web services from script. For more information, see How to: Configure WCF Services in ASP.NET AJAX.
· The service must be a class that implements an interface marked with ServiceContractAttribute. Individual service operations (methods) to be called from script must be qualified with the OperationContractAttribute attribute.
The following example shows a class that implements an interface that is marked with ServiceContractAttribute.
Using a WCF Service from Client Script in an ASP.NET Web Page
To call a WCF service from client script in an ASP.NET Web page, you first add a ScriptManager control to the page. You then declaratively set the ServiceReference object by adding an asp:ServiceReference child element to the ScriptManager control and setting its path attribute to point to the WCF service. The following example shows a service reference.
The ServiceReference object can reference a Web service only in the same domain. The Web service path can be relative, application relative, domain relative, or absolute. For absolute paths, you must make sure that the path is in the same domain.