Calling WebService in ASP.NET AJAX need to create a ServiceReference using ScriptManager>Services and using ScriptReference tag.
<asp:ScriptManager runat="server" ID="SM1"> <Services> <asp:ServiceReference Path="MathService.asmx" /> </Services> </asp:ScriptManager>
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 = "http://tempuri.org/")] [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.