RadComboBox Load on Demand with Web Service

14 posts, 0 answers
  1. Kenneth
    Kenneth avatar
    70 posts
    Member since:
    Feb 2008

    Posted 02 Feb 2009 Link to this post

    I am attempting to create a web service using the signature found in your example:

    [ScriptService]
    public class WebServiceName : WebService
    {
    [WebMethod]
    public RadComboBoxItemData[] WebServiceMethodName(object context)
    {
    // We cannot use a dictionary as a parameter, because it is only supported by script services.
    // The context object should be cast to a dictionary at runtime.
    IDictionary<string, object> contextDictionary = (IDictionary<string, object>) context;

    //...
    }
    }

    As I understand it, the web service must return a RadComboBoxItemData array. However, when creating a web service using the above signature, I get an error saying the RadComboBoxItemData implements IDictionary and therefore can not be serialized. I'm sure I'm doing something wrong - but can't figure it out. 

    I even took your sample code and compiled and got the same error!

    Regards,

    Ken

  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 02 Feb 2009 Link to this post

    Hello Kenneth,

    Our online example works as expected. What could be different in your case? Could you open a support ticket and send us an example which demonstrates the problem? Thanks.

    Regards,
    Albert
    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. Kenneth
    Kenneth avatar
    70 posts
    Member since:
    Feb 2008

    Posted 02 Feb 2009 Link to this post

    Here's my web service code:

    using

     

    System;

     

    using

     

    System.Collections;

     

    using

     

    System.Linq;

     

    using

     

    System.Web;

     

    using

     

    System.Web.Services;

     

    using

     

    System.Web.Services.Protocols;

     

    using

     

    System.Xml.Linq;

     

    using

     

    System.Web.Script.Services;

     

    using

     

    Telerik.Web.UI;

     

    [

    ScriptService]

     

    public

     

    class WebServiceName : WebService

     

    {

     

    public WebServiceName () { }

     

    [

    WebMethod]

     

     

    public RadComboBoxItemData[] WebServiceMethodName(object context)

     

    {

     

    return new RadComboBoxItemData[1];

     

    }

     

    }

    It compiles. However, when you connect to the web service (by http://localhost/MyApp/WebServices.asmx) you will get this error:

    Cannot serialize member Telerik.Web.UI.ControlItemData.Attributes of type System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] because it is an interface.


    I've written several web services and think I understand it pretty well. I ran into this problem by adding this to an existing project (which functions as a web service). Once I added the above, I could no longer connect to the web service. Instead I would get the error above. Since, creating a service with the above signature is required to get your controls using web services, I'm stuck!

    FYI -- I'm using VS 2008 with ASP.Net 3.5 SP 1. When I went to compile your on-line example, it required me to convert the solution to VS 2008. Perhaps the difference is that you haven't tested your example application in VS 2008.

  5. Kenneth
    Kenneth avatar
    70 posts
    Member since:
    Feb 2008

    Posted 02 Feb 2009 Link to this post

    To replicate, just create a new VS 2008 Project with the "ASP.NET Web Service Application" template. Enter the above code into the template, add "Telerik" as a project reference, press F5 to run. You will get this error:

    Cannot serialize member Telerik.Web.UI.ControlItemData.Attributes of type System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] because it is an interface.
  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 02 Feb 2009 Link to this post

    Hi Kenneth,

    This error occurs only when you browse the asmx file as the type IDictionary is not serializable for some reason. As strange as it sounds it all works when you request the service from client-side script. Anyway to solve the problem you should use a custom class instead of RadComboBoxItemData:

    class MyComboBoxItemData
    {
       public string Text {get; set;}
       public string Value {get;set;}
       //Add more properties if you need
    }

    [WebMethod]
    public MyComboBoxItemData[] GetData(object context)
    {
        return new MyComboBoxItemData[1];
    }

    Regards,
    Atanas Korchev
    the Telerik dev team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. laila
    laila avatar
    19 posts
    Member since:
    Nov 2006

    Posted 16 Feb 2009 Link to this post

    Hi, I too face the same problem..getting similar error what you gave for the example given in the telerik site. Can u tell me the solution if u got any?
    Thanks in advance....
  8. muthalagappan muthiah
    muthalagappan muthiah avatar
    5 posts
    Member since:
    Aug 2009

    Posted 25 Aug 2009 Link to this post

    Hi Telerik team,
    Could you please elaborate on your solution.
    Please post a sample (how to return tha radcomboboxitemdata)

    Regards
    Muthu
  9. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 26 Aug 2009 Link to this post

    Hello,

    This demo demonstrates the approach.

    Kind regards,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  10. muthalagappan muthiah
    muthalagappan muthiah avatar
    5 posts
    Member since:
    Aug 2009

    Posted 26 Aug 2009 Link to this post

    Hi Team,
    That really works.

    Thanks
    Muthu
  11. T F
    T F avatar
    8 posts
    Member since:
    May 2010

    Posted 08 Jun 2010 Link to this post

    Does this really work for anyone?  I receive the following error.

    The type Telerik.Web.UI.RadComboBoxContext is not supported because it implements IDictionary

    Here's a snippet of the code. 

    [

     

    WebService(Namespace = "http://tempuri.org/")]

     

    [

     

    WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

     

    [

     

    ScriptService]

     

     

     

    public class Instrument : System.Web.Services.WebService

     

    {

    [

     

    WebMethod]

     

     

     

    public IEnumerable GetItems(RadComboBoxContext context)

     

    {

     

     

    int numberOfItems = 1000;

     

     

     

    List<String> items = new List<String>();

     

     

     

    for (int i = 0; i < numberOfItems; i++)

     

    {

     

     

    String itemData = String.Empty;

     

    itemData =

     

    "Item " + i;

     

    items.Add(itemData);

    }

     

     

    return items;

     

    }

    }

  12. T F
    T F avatar
    8 posts
    Member since:
    May 2010

    Posted 09 Jun 2010 Link to this post

    I ended up resolving my issue.  RadComboBoxItemData implements IDictionary, which you cannot serialize.  Other examples showed IEnumerable, which I cannot serialize as well.  So I set everything to an object and it works.

    [

     

    WebMethod]

     

     

     

     

    public object[] AutoComplete(object context)  

     

     

    {

     

     

          IDictionary<string, object> _contextDictionary = (IDictionary<string, object>)context;

          

     

    string _filterString = ((string)_contextDictionary["FilterString"]).ToLower();

     

     

         

    List<RadComboBoxItemData> _rtnArray = new List<RadComboBoxItemData>();

     

     

         

     

    SqlConnection _sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["xxxx"].ConnectionString);

     

         

     

    SqlCommand _sqlComm = new SqlCommand(String.Format("xxxx @name='{0}'", _filterString), _sqlConn);

     

     

        SqlDataAdapter _adapter = null;

     

     

    try

     

     

    {

        _adapter = 

     

    new SqlDataAdapter(_sqlComm);

     

         

    DataTable _instruments = new DataTable();

     

        _adapter.Fill(_instruments);

     

     

        foreach (DataRow _row in _instruments.Rows)

         {

             

     

    RadComboBoxItemData _item = new RadComboBoxItemData();

     

             _item.Text = 

     

    String.Format("{0}-{1}", _row[0].ToString(), _row[1].ToString());

     

             _item.Value = _row[0].ToString();

            _rtnArray.Add(_item);

        }

    }

     

    catch (SqlException sqlEx){

     

        

     

    Mail.SendSqlError(sqlEx);

     

    }

     

    finally{

     

        _sqlConn.Close();

        _sqlConn.Dispose();

        _sqlComm.Dispose();

    }

     

        return _rtnArray.ToArray();

     

    }

     

  13. Shravan
    Shravan avatar
    10 posts
    Member since:
    Dec 2010

    Posted 15 Feb 2012 Link to this post

    How do I use a web service that is not available inline?
    Something like this....
    <telerik:RadComboBox ID="RadComboBox1" runat="server"
        EnableAutomaticLoadOnDemand="True" EnableItemCaching="True"
        EnableLoadOnDemand="True" Filter="Contains" HighlightTemplatedItems="True"
        IsCaseSensitive="True" ShowMoreResultsBox="True">
        <WebServiceSettings Method="AutoComplete_UserName"
            Path="http://localhost:3875/Auto.asmx" />
    </telerik:RadComboBox>
    <telerik:RadComboBox ID="RadComboBox1" runat="server"
        EnableAutomaticLoadOnDemand="True" EnableItemCaching="True"
        EnableLoadOnDemand="True" Filter="Contains" HighlightTemplatedItems="True"
        IsCaseSensitive="True" ShowMoreResultsBox="True">
        <WebServiceSettings Method="AutoComplete_UserName"
            Path="http://ServerName/Auto.asmx" />
    </telerik:RadComboBox>
  14. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 17 Feb 2012 Link to this post

    Hi Shravan,

    I am not quite sure that I undestand your scenario, but in general the application (where your RadComboBox page is) should be on the same domain as the service.

    Greetings,
    Kalina
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  15. sun
    sun avatar
    2 posts
    Member since:
    Mar 2015

    Posted 10 Mar 2015 in reply to Kenneth Link to this post

    Hello Kenneth,
    About this issue,you had solved it?
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017