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.
[ScriptService]
public class SimpleWebService : System.Web.Services.WebService
{
[WebMethod]
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.
type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/> 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 anyaction unless you want to disable the use of the SOAP protocol for the Webservices. In that case, you must enter the following configuration settingin the Web.config file.
No comments:
Post a Comment