Load-on-demand using WCF not working??

10 posts, 1 answers
  1. Alexandre
    Alexandre avatar
    13 posts
    Member since:
    Nov 2008

    Posted 16 Nov 2008 Link to this post

    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>
  2. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 17 Nov 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alexandre
    Alexandre avatar
    13 posts
    Member since:
    Nov 2008

    Posted 17 Nov 2008 Link to this post

    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;
    }
  5. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 18 Nov 2008 Link to this post

    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.
  6. Alexandre
    Alexandre avatar
    13 posts
    Member since:
    Nov 2008

    Posted 18 Nov 2008 Link to this post

    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.

  7. Answer
    Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 19 Nov 2008 Link to this post

    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.
  8. Alexandre
    Alexandre avatar
    13 posts
    Member since:
    Nov 2008

    Posted 19 Nov 2008 Link to this post

    One more time. Unbelievable support! Real thanks!
  9. Steele
    Steele avatar
    58 posts
    Member since:
    Jun 2006

    Posted 13 Dec 2008 Link to this post

    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?
  10. Alexandre
    Alexandre avatar
    13 posts
    Member since:
    Nov 2008

    Posted 13 Dec 2008 Link to this post

    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
  11. Joe
    Joe avatar
    48 posts
    Member since:
    Dec 2007

    Posted 17 Dec 2009 Link to this post

    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







Back to Top
UI for ASP.NET Ajax is Ready for VS 2017