This is used to call the Web Service using ASP.Net and Script Manager. Must be inserted in .aspx page.Â
<asp:ScriptManager runat=”server” ID=”scriptManager”> <Services> <asp:ServiceReference path=”WebService/TestService.asmx” /> </Services> </asp:ScriptManager>This is the script to call the web service method and print the result on the form:
<script type=”text/javascript”>Â Â Â Â Â Â Â var res1=0;
       var res2=0;
      Â
       LoadById(2);
      Â
       function initialize() {            document.getElementById(“javaControls”).className=””;
           document.write(res1);
           document.write(res2);
       }
      Â
       function OnSucceed(result) {
           res1=result[0];res2=result[1];
           initialize();
       }
      Â
       function LoadById(id) {
           TestService.GetResult(id, OnSucceed);
       }
      Â
       function LoadByDetail(testId) {
           TestService.GetResultByDetail(testId, OnSucceed);
       }
   </script> Â
Next is the Web Service “TestService”:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = “http://tempuri.org/“)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class SearchMap : System.Web.Services.WebService
{
  Â
   [WebMethod]
   public object[] GetResult(string id)
   {
       //get two results from database using id
       object[] results = { row[0], row[1] };
       return results;
   }
   [WebMethod]
   public object[] GetResultByDetail(string testId)
   {
       //get two results from database using test id
       object[] results = { row[0], row[1] };
       return results;
   }
}