Deepak M

Deepak M

  • 1.1k
  • 516
  • 32.6k

Unknown web method GetBankNames.

Dec 20 2019 4:04 AM
Web Service
  1. namespace WebApp1.Services  
  2. {  
  3.     /// <summary>  
  4.     /// Summary description for WebAppService  
  5.     /// </summary>  
  6.     [WebService(Namespace = "http://localhost/")]  
  7.     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]  
  8.     [System.ComponentModel.ToolboxItem(false)]  
  9.     // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.   
  10.     [ScriptService]  
  11.     public class WebAppService : WebService  
  12.     {  
  13.         [WebMethod]  
  14.         [ScriptMethod(ResponseFormat = ResponseFormat.Json)]  
  15.         public static List<string> GetBankNames(string pre)  
  16.         {  
  17.             List<string> listBanks = new List<string>();  
  18.             DataTable dtData = new DataTable();  
  19.             string conString = ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString;  
  20.             SqlConnection sqlCon = new SqlConnection(conString);  
  21.             sqlCon.Open();  
  22.             SqlCommand sqlCmd = new SqlCommand("Select BankId, BankName From BankMaster Where BankName Like '%' + @SearchText + '%'", sqlCon);  
  23.             sqlCmd.Parameters.AddWithValue("@SearchText", pre);  
  24.             SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);  
  25.             sqlDa.Fill(dtData);  
  26.             sqlCon.Close();  
  27.             if (dtData.Rows.Count > 0)  
  28.             {  
  29.                 for (int i = 0; i < dtData.Rows.Count; i++)  
  30.                 {  
  31.                     listBanks.Add(string.Format("{0}-{1}", dtData.Rows[i]["BankName"], dtData.Rows[i]["BankId"]));  
  32.                 }  
  33.             }  
  34.             return listBanks;  
  35.         }  
  36.     }  
  37. }  
 Script
  1. <script type="text/javascript">  
  2.     $(function () {  
  3.         $('#<%=txtAutoComplete.ClientID%>').autocomplete({  
  4.             minLength: 1,  
  5.             source: function (request, response) {  
  6.                 $.ajax({  
  7.                     url: "Services/WebAppService.asmx/GetBankNames",  
  8.                     data: "{ 'pre':'" + request.term + "'}",  
  9.                     dataType: "json",  
  10.                     type: "POST",  
  11.                     contentType: "application/json; charset=utf-8",  
  12.                     success: function (data) {  
  13.                         response($.map(data.d, function (item) {  
  14.                             return {  
  15.                                 label: item.split('-')[0],  
  16.                                 val: item.split('-')[1]  
  17.                             }  
  18.                         }))  
  19.                     },  
  20.                     error: function (response) {  
  21.                         alert(response.responseText);  
  22.                     },  
  23.                     failure: function (response) {  
  24.                         alert(response.responseText);  
  25.                     }  
  26.                 });  
  27.             },  
  28.             select: function (e, i) {  
  29.                 $("[id$=hfBankId]").val(i.item.val);  
  30.             },  
  31.         });  
  32.     });  
  33. </script>  
 When ever i call the web service always get error as "Unknown web method GetBankNames".

Answers (2)