How to call web services in ajax

Calling WebService in ASP.NET AJAX need to create a ServiceReference using ScriptManager>Services and using ScriptReference tag.

<asp:ScriptManager runat="server" ID="SM1">
<asp:ServiceReference Path="MathService.asmx" />

Here it is assumed that you have created a MathService.asmx web service. Note that when you create a web service in ASP.NET, it by default writes following attribute.

/// <summary>
/// Summary description for MathService
/// </summary>
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]

Notice the last line is commented. In order to call this web service from ASP.NET AJAX, we need to uncomment the last line.Now you are ready to call the web method.

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.