I have been struggling to bind an AutoComplete datasource to an AspNet web service throughout the day. But the web service is not called at all. The error routine shows "Internal Server Error" alert.
Both the web page and the web service are in a folder named "AutoComplete" under the root directory.
Could anybody please help me?
Client-Side Code:
<script type="text/javascript">
var _rootUrl = '<%=string.Format("{0}{1}/", Request.Url.GetLeftPart(UriPartial.Authority), HttpRuntime.AppDomainAppVirtualPath)%>';
</script>
<script type = "text/javascript">
$(document).ready(function ()
{
$("#TxtName").kendoAutoComplete(
{
change: function (e)
{
alert(e);
onChange(e);
},
minLength: 1,
dataTextField: "Name",
filter: "contains",
dataSource: new kendo.data.DataSource(
{
type: "json",
transport:
{
read:
{
type: "POST",
url: _rootUrl + "AutoComplete/WebService2.asmx/GetEmployeesNames",
contentType: 'application/json; charset=utf-8',
datatype: "json",
data: function ()
{
alert($("#TxtName").data("kendoAutoComplete").value());
return
{
Param: $("#TxtName").data("kendoAutoComplete").value()
}
} // data
}, //read
parameterMap: function (options)
{
alert(options);
return JSON.stringify(options);
} // parameterMap
}, // transport
serverFiltering: true,
serverSorting: true,
pageSize: 10,
schema:
{
data: "d"
},
error: function(e)
{
var xhr = e[0];
var statusCode = e[1];
var errorThrown = e[2];
alert(xhr);
alert(statusCode);
alert(errorThrown);
}
})
})
});
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID = "TxtName" runat = "server" />
</div>
</form>
</body>
Web Service:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService2 : System.Web.Services.WebService
{
public class Employee
{
private int _Id;
private string _Name;
public int Id
{
get { return _Id; }
set { _Id = value; }
}
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public Employee() { }
public Employee(int Id, string Name)
{
this.Id = Id; this.Name = Name;
}
}
public WebService2() { }
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public List<Employee> GetEmployeesNames(string Param)
{
string StrConnectionString = ConfigurationManager.ConnectionStrings["ConnectionStringEmployeesNormalized2"].ConnectionString;
SqlConnection SqlConnection1 = new SqlConnection(StrConnectionString);
SqlCommand SqlCommand1 = new SqlCommand("SELECT Id, Name FROM dbo.Employees Where Name Like '" + Param.Trim() + "%'", SqlConnection1);
DataTable DataTable1 = new DataTable();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter(SqlCommand1);
SqlDataAdapter1.Fill(DataTable1);
List<Employee> List1 = new List<Employee>();
foreach (DataRow DataRow1 in DataTable1.Rows)
{
List1.Add(new Employee(Convert.ToInt32(DataRow1["Id"]), Convert.ToString(DataRow1["Name"])));
}
return List1;
}
}
Both the web page and the web service are in a folder named "AutoComplete" under the root directory.
Could anybody please help me?
Client-Side Code:
<script type="text/javascript">
var _rootUrl = '<%=string.Format("{0}{1}/", Request.Url.GetLeftPart(UriPartial.Authority), HttpRuntime.AppDomainAppVirtualPath)%>';
</script>
<script type = "text/javascript">
$(document).ready(function ()
{
$("#TxtName").kendoAutoComplete(
{
change: function (e)
{
alert(e);
onChange(e);
},
minLength: 1,
dataTextField: "Name",
filter: "contains",
dataSource: new kendo.data.DataSource(
{
type: "json",
transport:
{
read:
{
type: "POST",
url: _rootUrl + "AutoComplete/WebService2.asmx/GetEmployeesNames",
contentType: 'application/json; charset=utf-8',
datatype: "json",
data: function ()
{
alert($("#TxtName").data("kendoAutoComplete").value());
return
{
Param: $("#TxtName").data("kendoAutoComplete").value()
}
} // data
}, //read
parameterMap: function (options)
{
alert(options);
return JSON.stringify(options);
} // parameterMap
}, // transport
serverFiltering: true,
serverSorting: true,
pageSize: 10,
schema:
{
data: "d"
},
error: function(e)
{
var xhr = e[0];
var statusCode = e[1];
var errorThrown = e[2];
alert(xhr);
alert(statusCode);
alert(errorThrown);
}
})
})
});
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID = "TxtName" runat = "server" />
</div>
</form>
</body>
Web Service:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService2 : System.Web.Services.WebService
{
public class Employee
{
private int _Id;
private string _Name;
public int Id
{
get { return _Id; }
set { _Id = value; }
}
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public Employee() { }
public Employee(int Id, string Name)
{
this.Id = Id; this.Name = Name;
}
}
public WebService2() { }
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public List<Employee> GetEmployeesNames(string Param)
{
string StrConnectionString = ConfigurationManager.ConnectionStrings["ConnectionStringEmployeesNormalized2"].ConnectionString;
SqlConnection SqlConnection1 = new SqlConnection(StrConnectionString);
SqlCommand SqlCommand1 = new SqlCommand("SELECT Id, Name FROM dbo.Employees Where Name Like '" + Param.Trim() + "%'", SqlConnection1);
DataTable DataTable1 = new DataTable();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter(SqlCommand1);
SqlDataAdapter1.Fill(DataTable1);
List<Employee> List1 = new List<Employee>();
foreach (DataRow DataRow1 in DataTable1.Rows)
{
List1.Add(new Employee(Convert.ToInt32(DataRow1["Id"]), Convert.ToString(DataRow1["Name"])));
}
return List1;
}
}