可以';t将SortedDictionary传递给WebService

本文关键字:WebService SortedDictionary 可以 | 更新日期: 2023-09-27 17:58:39

这是我的一个myasmx WebService方法的快速代码:

[WebMethod]
public static string Test(SortedDictionary<string, string> signature_additional_parameters)
{
    return "empty";
}

但上面写着:

不支持类型System.Collections.Generic.SortedDictionary `2[[System.String,mscorlib,Version=4.0.0,Culture=neutral,PublicKeyToken=223523TEASDV],[System.String,mscorllib,Version=40.0.0,Culture=neutrale,PublicKeyToken=2323TEASDV]],因为它实现了IDictionary

如果我设置了方法static,它就会工作,但此时我无法通过WebService调用该方法。

我该如何解决这个问题?

可以';t将SortedDictionary传递给WebService

字典(IDictionary)不可序列化。一个简单的解决方法是使用一个List,该List包含一个包含Key和Value类的类,并确保该键是唯一的。