在WebService中传递SortedList,ListDictionary 和 Hashtable 参数,如果直接传递,就会报错:System.NotSupportedException: The type System.Collections.sortedList is not
supported because it implements IDictionary.
通过集合类的copyTo 方法将其转化成DictionaryEntry 数组,再进行传递;客户端接收后,再将其转化成SortedList,ListDictionary 和 Hashtable 集合。
[WebMethod]
public DictionaryEntry[] HelloWorld()
{
SortedList sl = new SortedList();
sl.Add("Key","Value");
DictionaryEntry[] array = new DictionaryEntry[sl.Count];
sl.copyTo(array,0);
return array;
}
public void get(DictionaryEntry[] entries) { SortedList list = new SortedList(); foreach (DictionaryEntry entry in entries) { ist.Add(entry.Key,entry.Value); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。