This is a migrated thread and some comments may be shown as answers.

Load-on-demand using WCF not working??

9 Answers 267 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Alexandre
Top achievements
Rank 1
Alexandre asked on 16 Nov 2008, 02:56 PM
Using the Combo box with load-on-demand with "WCF" don't show any text values. The call to the webservice is working fine but there is no text-values displayed in the dropdown. The combo box containted 10 empty elements without any text values..?

Please help.

Here is my simplecode

ILocationService.cs
[ServiceContract]
public interface ILocationService
{
    [OperationContract]
    RadComboBoxItemData[] GetCountries();
}

LocationService.cs
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class LocationService : ILocationService
{
    public RadComboBoxItemData[] GetCountries()
    {
        List<RadComboBoxItemData> result = new List<RadComboBoxItemData>();
        for (int i = 0; i < 10; i++)
        {
            RadComboBoxItemData itemData = new RadComboBoxItemData();
            itemData.Text = "Item" + i.ToString();
            itemData.Value = i.ToString();
            result.Add(itemData);
        }
        return result.ToArray();
    }
}

LocationService.svc
<%@ ServiceHost Language="C#" Debug="true" Service="LocationService" CodeBehind="~/App_Code/LocationService/LocationService.cs" %>

TestSVC.aspx
        <telerik:RadComboBox ID="drpCountry" runat="server" EnableLoadOnDemand="True">
            <WebServiceSettings Method="GetCountries" Path="~/WebServices/LocationService.svc" />
        </telerik:RadComboBox>

9 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 17 Nov 2008, 02:41 PM
Hello Alexandre,

WCF WebService uses DataContractJsonSerializer which is different as the ASP.NET AJAX JavascriptSerializer. For example, the DataContractJsonSerializer represents a dictionary as an array of key/value pairs, whereas the ASP.NET AJAX JavascriptSerializer represents a dictionary as actual JSON objects. This is the reason of the problem.

Please find the attached sample project illustrating how to achieve this scenario. All you need to do is to add the ComboInfo class to your application and use it instead of the RadComboBoxItemData class

For more details please read this MSDN article .


Regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alexandre
Top achievements
Rank 1
answered on 17 Nov 2008, 03:57 PM
Perfectly works! But.. can't pass any parameters to the web services... When implementing the second level i need to pass the selected country id and then request the web-service but parameters all always null.. Any Idea?

TestSVC.aspx
        <telerik:RadComboBox ID="drpCountry" runat="server" EnableLoadOnDemand="True" OnClientSelectedIndexChanged="OnClientSelectedIndexChangedCountries">
            <WebServiceSettings Method="GetCountries" Path="~/WebServices/LocationService.svc" />
        </telerik:RadComboBox>



<telerik:RadComboBox ID="drpStates" runat="server" EnableLoadOnDemand="false" >
    <WebServiceSettings Method="GetStates" Path="~/WebServices/LocationService.svc" />
</telerik:RadComboBox>

Javascript
    function OnClientSelectedIndexChangedCountries(sender, eventArgs) {
        var oSelectedItem = eventArgs.get_item();
        var oComboStates = $find("<%= drpStates.ClientID %>");
        oComboStates.clearSelection();
        oComboStates.requestItems(oSelectedItem.get_value(), false);
    }

LocationService.cs (try with standard object and with DataContract object..... does'nt work.
    [OperationContract]
    public LocationItem[] GetStates(LocationParameters p_oParams)
    {
     .....
    }
   or
    [OperationContract]
    public LocationItem[] GetStates(object p_oParams)
    {
     .....
    }

LocationParameters.cs
[DataContract]
public class LocationParameters
{   
    [DataMember]
    public string Value;
}
0
Rosi
Telerik team
answered on 18 Nov 2008, 07:01 AM
Hi Alexandre,

I suggest you use the context property of RadComboBox to implement the task. Please read our help article Passing Context Information to the Server  for more details.

Regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alexandre
Top achievements
Rank 1
answered on 18 Nov 2008, 01:55 PM
Hi, this working fine if using a asmx webservice, but did'nt with a WCF.
I'Ve try all of these and value are always null or containt no values.

JavaScript
    function OnClientItemsRequestingStates(sender, eventArgs) {
        var comboCountries = $find("<%= drpCountries.ClientID %>");        
        var context = eventArgs.get_context();
        context["FilterString"] = comboCountries.get_value();
       alert(context["FilterString"]); //it show the correct value
    }

LocationService.cs
[OperationContract]
public LocationItem[] GetStates(LocationParameters context) { .... }
or
[OperationContract]
public LocationItem[] GetStates(object context) { .... }



LocationParameters.cs  (I've try all those possible values)
[DataContract]
public class LocationParameters
{   
    [DataMember]
    public string Value;
    or
    [DataMember]
    public RadComboBoxContext Value;
    or
    [DataMember]
    public object Value;
    or
    [DataMember]
    public RadComboBoxContext Value;



}

Have also try
[OperationContract]
public LocationItem[] GetStates(RadComboBoxContext context) {
     IDictionary<string, object> contextDictionary = (IDictionary<string, object>)context;
     //But there the contextDictionary containt a "RadComboBoxContext" with not element, + Keys and Values with no element.
}

Any suggestion, cause it seems that it's not supported with WCF...
Please help..
Thanks.

0
Accepted
Rosi
Telerik team
answered on 19 Nov 2008, 06:51 AM
Hello Alexandre,

Please find attached the modified project.

Greetings,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alexandre
Top achievements
Rank 1
answered on 19 Nov 2008, 12:26 PM
One more time. Unbelievable support! Real thanks!
0
Steele
Top achievements
Rank 1
answered on 13 Dec 2008, 08:28 PM
This Demo does work, but it destroys the ItemTemplate and the DataTextFields and DataValueFields
I know this was asked for earlier this year and the answer was no...
but can this be done while retaining the ItemTemplate yet?
0
Alexandre
Top achievements
Rank 1
answered on 13 Dec 2008, 09:33 PM
Sorry Steele , you ma do something wrong, cause thise demo "107326_WCFDemo.zip" is working just perfectly!!
Try to repost your question from a other thread, cause thise one has ben awnser very well.

sorry
0
Joe
Top achievements
Rank 2
answered on 18 Dec 2009, 12:05 AM
Rosi,

Your example works but when I try moving it to my project I am still having problems reading the parameters. I see in Fiddler that your context (the one that works) is encoded as follows:

{"context":{"NumberOfItems":0,"Text":"a","FilterString":"a"}}

My practically identical object does not work and the context looks like this:

{"context":[{"Key":"Text","Value":"a"},{"Key":"NumberOfItems","Value":0},{"Key":"FilterString","Value":"a"}]}

Do you know if this is caused by a configuration problem in my service or is it something on the client side?

Thanks,
Joe







Tags
ComboBox
Asked by
Alexandre
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Alexandre
Top achievements
Rank 1
Steele
Top achievements
Rank 1
Joe
Top achievements
Rank 2
Share this question
or