【发布时间】:2014-01-08 12:10:30
【问题描述】:
我必须开发一个非常复杂的 ASP.Net Web 服务。以下是我编写的示例代码。
首先,我有一个以 List 作为参数的 Web 服务方法。
[WebMethod] public AppResults SyncObjectToServer(string appID, List updates)
WSExecCommand 是我定义的一个包含多个 List 对象的类。这是WSExecCommand 的简化版本。
[Serializable] public class WSExecCommand
{
public string Command;
[XmlIgnore] public Dictionary<string, MyKeyValuePair> __ParentKey;
[XmlArray] public List<MyKeyValuePair> ParentKey
{
get
{
if (__ParentKey == null)
__ParentKey = new Dictionary<string, MyKeyValuePair>;
return new List<KeyValuePair>(__ParentKey.Values);
}
set
{
__ParentKey.Clear();
foreach (MyKeyValuePair kvp in value)
__ParentKey.Add(kvp.Key, kvp);
}
}
}
如果你想知道我为什么要这样设置我的类,问题是 ASP.Net 不允许你返回或接收 Dictionary 对象。我真的需要将我的 ParentKey 对象作为字典。但是,为了绕过 ASP.Net 的限制,我创建了上述包装器属性来获取和设置底层 Dictionary 的值,我在代码中引用了它。
我的问题是,当我从我的消费应用程序调用我的 Web 服务方法时,__ParentKey 永远不会填充传递给服务器的数据。
我已经进入了 Web 服务代码,我得到了一个填充的 List<WSExecCommand> 集合。但是,对于列表中的每个WSExecCommand,所有List<T> 类型的对象都有0 个项目。
我该如何解决这个问题?
【问题讨论】:
标签: c# asp.net .net web-services collections