【问题标题】:Can't pass a SortedDictionary to a WebService?不能将 SortedDictionary 传递给 WebService?
【发布时间】:2014-04-16 18:22:33
【问题描述】:

这是我的asmx 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.0, Culture=neutral, PublicKeyToken=23523TEASDV],[System.String, mscorlib, Version=4.0 .0.0, Culture=neutral, PublicKeyToken=23523TEASDV]] 不受支持,因为它实现了 IDictionary。

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

我该如何解决这个问题?

【问题讨论】:

标签: c# .net web-services dictionary static


【解决方案1】:

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

【讨论】:

  • 但是如果我需要这个类,我还需要在客户端调用者上定义它。这就是分散整个系统。
  • @markzzz 不是真的。与 wcf 一样,它在客户端制作数据合约的副本。它只是定义了您交换数据的方式。如果这确实是一个问题,您可以使用格式为 {0};{1} 的字符串,然后将其拆分,但我不会这样做。
猜你喜欢
  • 2016-11-04
  • 2011-07-23
  • 2011-12-17
  • 2011-11-21
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
  • 2011-08-15
  • 2012-10-11
相关资源
最近更新 更多