我有一个 Web 服务,当被调用时,它返回一个包含多态列表的结果对象。但是,当我在我的客户端应用程序中添加引用时,公共(public)字段在客户端应用程序中变成了一个 Country 数组。如何将客户端应用程序中的字段更改为列表?
public Result GetCountryList()
{
List<Country> countries = GrabCountryList();
Result result = new Result();
result.theResult = countries;
}
这是公共(public)属性(property)
public object theResult
{
get {return _theResult; }
set {_theResult = value;}
}
来自 Mehmet Aras 的接受的答案:
右键单击服务引用,然后选择“配置引用”。在集合类型下,选择 System.Collection.Generic.List。更新服务引用,一切顺利。
感谢 Matt Hamilton 提出的从数组创建新列表的建议。
最佳答案
我相信您必须自己重建列表。 Web 服务应该与语言无关,并且自 List<T>
是 .NET 框架的一部分,它不能是序列化返回值的一部分。
重建列表非常简单:
var countries = new List<Country>(result.theResult);
关于c# - List<Country> 成为 Country [] 跨网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/833767/