几年前我写了一个WCF服务,它运行在IIS下的Windows 2003服务器上。我使用 VS 2008 和 .NET 3.5 编写了它。有问题的代码是这样的:
public static List<ASILookupTables> GetLookupTableAux(bool UseProduction)
{
ASIClassesDataContext dcASI = new ASIClassesDataContext();
var result = from lookups in dcASI.ASILookupTables4s
orderby lookups.SortOrder
select lookups;
List<ASILookupTables> list = new List<ASILookupTables>();
foreach (var item in result)
{
ASILookupTables alt = new ASILookupTables();
//more lines to add other elements
list.Add(alt);
}
return list;
}
现在我正在使用 .NET 4.0 编写一个 VS 2010 应用程序来使用它。 VS 2010 应用程序中有问题的代码片段是这样的:
LookupSvc.LookupsClient proxy = new LookupSvc.LookupsClient();
//retrieve list of lookup tables
List<LookupSvc.ASILookupTables> lookupTables = proxy.GetLookupTableAux(true);
但是,我收到以下错误:
“无法将类型‘AsiEF.LookupSvc.ASILookupTables[]’隐式转换为‘System.Collections.Generic.List’”
我不明白;在 WCF 代码中,在我看来我正在返回一个列表。看起来我没有返回一个数组。是因为WCF服务是.NET 3.5而我的新项目是.NET 4.0吗?
最佳答案
如果您希望代理使用 List<T>
,您可以更改服务引用设置或 T[]
.
要更改设置,请在解决方案资源管理器中右键单击项目中的服务引用。选择“配置服务引用”。在“收藏类型”中选择 System.Collections.Generic.List
.
关于.net - 获取 "Cannot implicitly convert type ' 表 [ ]' to ' Generic.List<>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9100768/