Web Service- namespace WebApp1.Services
- {
-
-
-
- [WebService(Namespace = "http://localhost/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
-
- [ScriptService]
- public class WebAppService : WebService
- {
- [WebMethod]
- [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
- public static List<string> GetBankNames(string pre)
- {
- List<string> listBanks = new List<string>();
- DataTable dtData = new DataTable();
- string conString = ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString;
- SqlConnection sqlCon = new SqlConnection(conString);
- sqlCon.Open();
- SqlCommand sqlCmd = new SqlCommand("Select BankId, BankName From BankMaster Where BankName Like '%' + @SearchText + '%'", sqlCon);
- sqlCmd.Parameters.AddWithValue("@SearchText", pre);
- SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
- sqlDa.Fill(dtData);
- sqlCon.Close();
- if (dtData.Rows.Count > 0)
- {
- for (int i = 0; i < dtData.Rows.Count; i++)
- {
- listBanks.Add(string.Format("{0}-{1}", dtData.Rows[i]["BankName"], dtData.Rows[i]["BankId"]));
- }
- }
- return listBanks;
- }
- }
- }
Script- <script type="text/javascript">
- $(function () {
- $('#<%=txtAutoComplete.ClientID%>').autocomplete({
- minLength: 1,
- source: function (request, response) {
- $.ajax({
- url: "Services/WebAppService.asmx/GetBankNames",
- data: "{ 'pre':'" + request.term + "'}",
- dataType: "json",
- type: "POST",
- contentType: "application/json; charset=utf-8",
- success: function (data) {
- response($.map(data.d, function (item) {
- return {
- label: item.split('-')[0],
- val: item.split('-')[1]
- }
- }))
- },
- error: function (response) {
- alert(response.responseText);
- },
- failure: function (response) {
- alert(response.responseText);
- }
- });
- },
- select: function (e, i) {
- $("[id$=hfBankId]").val(i.item.val);
- },
- });
- });
- </script>
When ever i call the web service always get error as "Unknown web method GetBankNames".