Wednesday, July 27, 2011

Making Web Services Accessible from Script

In order for a Web service to be accessed from script, it must be an .asmx Web service whose Web service class is qualified with the ScriptServiceAttribute attribute. Individual methods to be called from script must be qualified with the WebMethodAttribute attribute.

The following example shows these attributes in Web service code.

public class SimpleWebService : System.Web.Services.WebService

public string EchoInput(String input)
// Method code goes here.

To enable Web service calls from script, 
you must register the ScriptHandlerFactory HTTP handler in the application's
 Web.config file. The handler processes calls made from script to .asmx 
Web services. 
The following example shows the Web.config element for adding the handler. 



For Web service calls that are not issued from ASP.NET AJAX script,
the ScriptHandlerFactory handler delegates the call to the default handler,
which uses SOAP instead of JSON format.
The delegation is performed automatically and you do not have to take any
action unless you want to disable the use of the SOAP protocol for the Web
services. In that case, you must enter the following configuration setting
in the Web.config file.

No comments:

Post a Comment