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
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.
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.
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.
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,
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thanks in advance....
Could you please elaborate on your solution.
Please post a sample (how to return tha radcomboboxitemdata)
Regards
Muthu
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.
That really works.
Thanks
Muthu
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;
}
}
[
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();
}
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
>
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
About this issue,you had solved it?