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

RadComboBox Load on Demand with Web Service

13 Answers 894 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 1
Kenneth asked on 02 Feb 2009, 07:01 AM

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

13 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Feb 2009, 08:39 AM
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.
0
Kenneth
Top achievements
Rank 1
answered on 02 Feb 2009, 08:59 AM
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.

0
Kenneth
Top achievements
Rank 1
answered on 02 Feb 2009, 09:11 AM
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.
0
Atanas Korchev
Telerik team
answered on 02 Feb 2009, 09:44 AM
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.
0
laila
Top achievements
Rank 1
answered on 16 Feb 2009, 08:32 AM
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....
0
muthalagappan muthiah
Top achievements
Rank 1
answered on 25 Aug 2009, 08:58 AM
Hi Telerik team,
Could you please elaborate on your solution.
Please post a sample (how to return tha radcomboboxitemdata)

Regards
Muthu
0
Veselin Vasilev
Telerik team
answered on 26 Aug 2009, 08:27 AM
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.
0
muthalagappan muthiah
Top achievements
Rank 1
answered on 26 Aug 2009, 09:15 AM
Hi Team,
That really works.

Thanks
Muthu
0
T F
Top achievements
Rank 1
answered on 08 Jun 2010, 11:07 PM
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;

 

}

}

0
T F
Top achievements
Rank 1
answered on 09 Jun 2010, 02:42 PM
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();

 

}

 

0
Shravan
Top achievements
Rank 1
answered on 15 Feb 2012, 05:35 PM
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>
0
Kalina
Telerik team
answered on 17 Feb 2012, 04:22 PM
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 >>
0
sun
Top achievements
Rank 1
answered on 10 Mar 2015, 10:24 AM
Hello Kenneth,
About this issue,you had solved it?
Tags
ComboBox
Asked by
Kenneth
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Kenneth
Top achievements
Rank 1
laila
Top achievements
Rank 1
muthalagappan muthiah
Top achievements
Rank 1
Veselin Vasilev
Telerik team
T F
Top achievements
Rank 1
Shravan
Top achievements
Rank 1
Kalina
Telerik team
sun
Top achievements
Rank 1
Share this question
or