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

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

11 Answers 770 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Chet Watkins
Top achievements
Rank 1
Chet Watkins asked on 29 Jan 2009, 02:21 PM
I am trying to create a web service using the demo "Boosting Performance with WebServices". When I try to implement the web service, I keep getting this error.

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

Does anyone know how I can get around this or what I am doing wrong from the demo?

Thanks.

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.Services;  
using Telerik.Web.UI;  
using System.Collections;  
using System.Runtime.Serialization;  
using System.Runtime.Serialization.Formatters.Soap;  
 
 
namespace testCombo  
{  
    /// <summary>  
    /// Summary description for TestWebService  
    /// </summary>  
    [WebService(Namespace = "http://tempuri.org/")]  
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]  
    [System.ComponentModel.ToolboxItem(false)]  
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.   
    //[System.Web.Script.Services.ScriptService]  
    public class TestWebService : System.Web.Services.WebService  
    {  
          
        [WebMethod]  
        public IEnumerable GetItems(RadComboBoxContext context)  
        {  
            int numberOfItems = 1000;  
            List<ComboBoxItemData> items = new List<ComboBoxItemData>();  
            for (int i = 0; i < numberOfItems; i++)  
            {  
                ComboBoxItemData itemData = new ComboBoxItemData();  
                itemData.Text = "Item " + i;  
                items.Add(itemData);  
            }  
 
            return items;  
        }  
 
 
        class ComboBoxItemData  
        {  
            private string text;  
 
            public string Text  
            {  
                get { return text; }  
                set { text = value; }  
            }  
        }  
 
 
    }  


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="testCombo._Default" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!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 runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
        </telerik:RadScriptManager> 
        <telerik:RadComboBox ID="RadComboBox1" runat="server"   
         EnableLoadOnDemand="true">  
        <ExpandAnimation Type="none" /> 
                    <CollapseAnimation Type="none" /> 
                    <WebServiceSettings Path="TestWebService.asmx" Method="GetItems" /> 
        </telerik:RadComboBox> 
    </div> 
    </form> 
</body> 
</html> 

11 Answers, 1 is accepted

Sort by
0
Chet Watkins
Top achievements
Rank 1
answered on 29 Jan 2009, 07:21 PM
I found the answer to this in the PDF they have on the site, it is a Visual Studio issue. Thanks.
0
Rick
Top achievements
Rank 2
answered on 08 Feb 2009, 12:42 PM
Please clarify where we would find "the PDF they have on the site".

    Rick.
0
Voss Grose
Top achievements
Rank 1
answered on 08 Feb 2009, 05:44 PM
Do you have a link to this PDF?
0
Rick
Top achievements
Rank 2
answered on 08 Feb 2009, 11:09 PM
I finally found it. The PDF he is referring to is the manual, which is available at: http://www.telerik.com/documents/RadControlsAJAXCourseware.pdf. The reference was a bit difficult o find. It's on page 407 of the manual (or 419 according to the PDF file itself).

What it says is:

When implementing the Web Service, any Web Method that supports the load-on-demand mechanism must take

a single parameter, which supplies context information about the request. This parameter is of type

RadComboBoxContext

, but it can also be cast to IDictionary to read context information that is added in an

 

OnClientItemsRequesting

event handler.

 

Gotcha!

Because the context parameter is an IDictionary value, you cannot run the Web Service

 

directly from within Visual Studio. When running the example, select Default.aspx before hitting

F5 or Ctrl-F5.

 

Rick.

0
Rick
Top achievements
Rank 2
answered on 10 Feb 2009, 02:08 AM
I still don't understand why this doesn't work under Visual Studio when it works on a real server. It creates a major drawback to using web services to populate a combo box in that debugging becomes much more difficult.

The article at http://msmvps.com/blogs/rakeshrajan/archive/2006/01/15/81105.aspx explains how to get around the serialization issue simply by implementing System.XML.IXMLSerializable on the class. In this case, the class that would need to implement IXMLSerializable would be the RadComboBoxContext class. Unfortunately we don't have control of this class. But couldn't Telerik implement IXMLSerializable on the class and solve this problem?

Does anybody understand why this problem exists in Visual Studio and why the same problem doesn't happen on a real server?

Is there some way to get around it for debugging?

Rick.
0
Atanas Korchev
Telerik team
answered on 10 Feb 2009, 08:06 AM
Hi Rick,

By design the WebService serializer cannot serialize dictionaries when you try to call as web service from server-side code (or request the .asmx file). However this does not cause any issues if the web service is called from client-side (javascript). If you need to browse the asmx or call the same method from server-side code I suggest you use a custom class instead of RadComboBoxItemData or RadComboBoxContext. Here is a short example

[WebMethod]
public MyItemData[] GetItems(MyContext context)
{
     //return data
}

public class MyItemData
{
     public string Text {get;set;}
     public string Value {get;set;}
     //Add more properties if you want to
}
public class MyContext
{
    public string Text {get;set;}
    public int NumberOfItems {get;set;}
}

I have logged the solution from this blog post for further investigation.

I hope this helps,
Atanas Korchev
the Telerik dev team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Russ
Top achievements
Rank 1
answered on 10 Feb 2009, 01:08 PM
Rick,

You might have been seeing the same problem I was.  Typically (in my limited use of web services) I would create web services within an independent project from my main application's project in Visual Studio.   Doing this was giving me the same issues you seem to be describing.   To correct those issues, I created my new web service for the RadComboBoxes as a new item within my main application project, just under it's own sub-folder for seperation (so just a new asmx file and code behind class, within the project's new folder).  

By keeping it within the same application project I am able to still add the web service path to the RadComboBoxes <WebServiceSettings> and now debug the web service (i.e. breakpoints, watches, etc are available and working within the web service) as well as use the base code similar to that found in the examples on the site here (i.e. returning RadComboBoxItemData[] and using a parameter of RadComboBoxContext context).

Hope that helps.

Russell.
0
Rick
Top achievements
Rank 2
answered on 10 Feb 2009, 02:39 PM
Russell,

    Thanks for replying. However, my web services are not in a separate project. They are just in a subfolder of my project as you suggest. I don't have a handle on this probem yet, but I am encouraged that you have been able to debug your web services.

    Rick.
0
Rick
Top achievements
Rank 2
answered on 18 Feb 2009, 03:38 PM
Apparently, based on my recent conversation with Tech Support, this problem can be solved by using a custom class for passing the data to and from the web service, such as:


[WebMethod]  
public MyItemData[] GetItems(MyContext context)  
{  
     //return data  
}  
 
public class MyItemData  
{  
     public string Text {get;set;}  
     public string Value {get;set;}  
     //Add more properties if you want to  
}  

public class MyContext  
{  
    public string Text {get;set;}  
    public int NumberOfItems {get;set;}  
}  
 

Though I haven't tried it yet, they tell me that the custom class will be automatically detected (I'm guessing using reflection?). I'll try it when I get a chance and post the results, but it's encouraging.

If this really does work, it seems to me that it would be cleaner and more intuitive if Telerik had designed the interface to the WebService to use an Interface rather than an actual Class (e.g. IComboBoxContext), but there may be some reason they could not do this (such as backward compatibility).

Rick.
0
Roger Middleton
Top achievements
Rank 1
answered on 11 Feb 2010, 04:28 AM
Rick,

Did you ever figure this out?

Thanks,
Roger
0
Rick
Top achievements
Rank 2
answered on 11 Feb 2010, 03:54 PM
Roger,

    Yes. I am no longer having this problem. However, it's been so long that I've forgotten the details. As I recall, the solution was to make the parameter to the web service method an object and then cast it in the method. This prevents the Visual Studio debugger from getting upset about the RadComboBoxContext.

   My web method now looks like this:

    [WebMethod]  
    public RadComboBoxData GetData(object context)  
    {  
        var dictContext = (IDictionary<string, object>)context;  
 
        string wellIdString = (string)dictContext["WellID"];  
 
... 
Tags
ComboBox
Asked by
Chet Watkins
Top achievements
Rank 1
Answers by
Chet Watkins
Top achievements
Rank 1
Rick
Top achievements
Rank 2
Voss Grose
Top achievements
Rank 1
Atanas Korchev
Telerik team
Russ
Top achievements
Rank 1
Roger Middleton
Top achievements
Rank 1
Share this question
or