Installed Telerik components: RadControls for ASP.NET AJAX Q2 2011 SP1
Text:
I created two projects, a WFC Service (name: PartialProjectServiceAjaxTest) and a Web Application (name: PartialProjectASPXAjaxTest).
The service in his basic form, was a copy of the code on http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/linqdatasource/defaultcs.aspx.
The important changes in the code:
- Add a list <person> and read this list with LINQ
The aspx in his basic form, was a copy of http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/autocompleteclientside/defaultcs.aspx
The important changes in the code:
- add RadScriptManager1
- <WebServiceSettings Path="http://localhost:54266/Service1.svc" Method="LoadData" /></telerik:RadComboBox> (54266 is the used port)
When i deploy the projects, it’s possible to see the UI, but when i will show up the results of the service, in the ComboBox, i will get an error message:
‘The server method ’LoadData’ failed’
This message is parsed right after clicking the textbox in the UI.
Testing:
- First i created a console app to test the service. Because i could load the data, the service doesn’t generate the error;
- Then i commented the code that filter the results. I need data anyway and will filter them in a later stage. I got the same error;
-Debugging both of the projects doesn’t give any explanation;
My question is: Why isn’t it possible for me to load the LoadData method in my Web app in case of a good functioning service?
The most inportant code:
LodWebService.aspx:____________________________________________________________________________________________________
<%
@ Page Language="C#" AutoEventWireup="true" CodeBehind="LodWebService.aspx.cs" Inherits="LodWebService" %>
<%
@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head id="Head1" runat="server">
<title></title>
<style type="text/css">
span.text
{
font: 13px 'Segoe UI' , Arial, sans-serif;
color: #4888a2;
padding-right: 10px;
vertical-align: middle;
display: inline-block;
*
display:inline;
zoom:1;
width:90px;
}
.module-row
{
margin: 10px 0;
}
.module-row .status-text
{
margin-left: 103px;
display: block;
font: 13px 'Segoe UI' , Arial, sans-serif;
color: #4888a2;
}
</style>
<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</
head>
<
body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
<Scripts>
<%
--Needed for JavaScript IntelliSense in VS2010--%>
<%
--For VS2008 replace RadScriptManager with ScriptManager--%>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
</Scripts>
</telerik:RadScriptManager>
<script type="text/javascript">
//Put your JavaScript code here.
</script>
<div class="module-row">
<span class="text"></span>
<telerik:RadComboBox ID="RadComboBox1" runat="server" Width="400px" Height="150px"
EmptyMessage="E-mail adres / Achternaam / Voornaam" EnableLoadOnDemand="true" ShowMoreResultsBox="true"
EnableVirtualScrolling="true">
<WebServiceSettings Path="http://localhost:54266/Service1.svc" Method="LoadData" />
</telerik:RadComboBox>
<asp:Button runat="server" Text="Select" ID="Button1" OnClick="Button1_Click">
</asp:Button>
</div>
<div class="module-row">
<asp:Label CssClass="status-text" ID="Label1" runat="server"></asp:Label>
</div>
</form>
</
body>
</
html>
Service1.svc:____________________________________________________________________________________________________
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Runtime.Serialization;
using
System.ServiceModel;
using
System.Text;
using
System.ServiceModel.Activation;
using
Telerik.Web.UI;
namespace
partialProjectServiceAjaxTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
[
AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public class person
{
public string firstname;
public string lastname;
}
RadComboBoxData IService1.LoadData(RadComboBoxContext context)
{
//The RadComboBoxData object contains all required information for load on demand:
// - the items
// - are there more items in case of paging
// - status message to be displayed (which is optional)
RadComboBoxData result = new RadComboBoxData();
/// NorthwindDataContext northwind = new NorthwindDataContext();
List<person> persons = new List<person>();
persons.Add(
new person { firstname = "Bernard", lastname = "C" });
persons.Add(
new person { firstname = "Theo", lastname = "C" });
persons.Add(
new person { firstname = "Bryan", lastname = "C" });
persons.Add(
new person { firstname = "Tim", lastname = "C" });
//Get all items from the Customers table. This query will not be executed untill the ToArray method is called.
var allCustomers = from customer in persons
orderby customer.firstname
select new RadComboBoxItemData
{
Text = customer.firstname
};
////In case the user typed something - filter the result set
//string text = context.Text;
//if (!String.IsNullOrEmpty(text))
//{
// allCustomers = allCustomers.Where(item => item.Text.StartsWith(text));
//}
////Perform the paging
//// - first skip the amount of items already populated
//// - take the next 10 items
//int numberOfItems = context.NumberOfItems;
//var customers = allCustomers.Skip(1).Take(10);
////This will execute the database query and return the data as an array of RadComboBoxItemData objects
//result.Items = customers.ToArray();
//int endOffset = numberOfItems + customers.Count();
//int totalCount = allCustomers.Count();
////Check if all items are populated (this is the last page)
//if (endOffset == totalCount)
// result.EndOfItems = true;
//////Initialize the status message
//result.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>",
// endOffset, totalCount);
result.Items = allCustomers.ToArray();
return result;
}
}
}
IService1.cs:_________________________________________________________________________________
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Runtime.Serialization;
using
System.ServiceModel;
using
System.Text;
using
Telerik.Web.UI;
namespace
partialProjectServiceAjaxTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[
ServiceContract]
public interface IService1
{
[
OperationContract]
RadComboBoxData LoadData(RadComboBoxContext context);
}
}