WCF 代理返回数组而不是列表,即使集合类型 == Generic.List [英] WCF Proxy Returning Array instead of List EVEN THOUGH Collection Type == Generic.List

查看:28
本文介绍了WCF 代理返回数组而不是列表,即使集合类型 == Generic.List的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 VS 2010 解决方案,其中包含一个 WCF 库项目和另一个使用该 Web 服务的项目.在VS 2012中打开后,进行了升级.

I have a VS 2010 solution containing a WCF Library project and another project consuming that web service. After opening in VS 2012, it was upgraded.

代理现在将 List 类型作为数组返回,即使 CollectionMappings 明确设置为 Generic.List.

The proxy now returns List<T> types as arrays, even though CollectionMappings is clearly set to Generic.List.

会发生什么?

其他人也有类似的问题 here 但他从 VS 2012 降级到 VS 2010.

Someone else has a similar problem here but he was downgrading from VS 2012 to VS 2010 instead.

我仔细检查过,Reference.svcmap 包含:

I double checked, and Reference.svcmap contains:

<CollectionMappings>
  <CollectionMapping TypeName="System.Collections.Generic.List`1" Category="List" />
</CollectionMappings>

但 Reference.cs 包含以下内容:

but Reference.cs contains stuff such as:

 public xxx.ServiceReference1.ADUser[] get_ADUsers;

在网络服务中时:

 public List<ADUser> get_ADUsers(string wildcard, string sortexp, string sortorder)

更多信息(2012 年 12 月 12 日添加):

More info (added Dec 12, 2012):

在 VS2010 中创建的解决方案在另一台 PC 上运行良好.它已从那台 PC 签入 TFS.在这台有问题的 PC 上,我们进行了映射和 GET.当我们尝试构建时,我们遇到了错误,其中服务引用中使用的所有 List 类型都以某种方式被视为数组.我们在有问题的 PC 上安装了 VS 2010 并获得了该解决方案.同样的错误也存在.因此,它似乎与 VS 2012 无关.

The solution, created in VS2010, was working fine on another PC. It was checked into TFS from that PC. On this problematic PC, we did a mapping and GET. When we try to build, we got that error where all the List<T> types used in the service reference were all somehow treated as arrays. We installed VS 2010 on the problematic PC and GET that solution too. And the same error is also there. So, it appears it is not related to VS 2012.

所有电脑都是 Windows 7 Professional.

All PCs are Windows 7 Professional.

更多信息(2012 年 12 月 19 日添加):

More info (added Dec 19, 2012):

项目打开时,本地PC上的ServiceReferences/ServiceReference1/Reference.cs自动修改.变化是巨大的.以下是其中的一小部分:

When the project was opened, ServiceReferences/ServiceReference1/Reference.cs on the local PC was modified automatically. The changes were huge. Below is a small part of it:

显示了两种方法.List get_Hotlines() 变成 string[] get_Hotlines() 并且 List get_HotlinesBySite() 变成 string[] get_HotlinesBySite().

Two methods are shown. List<string> get_Hotlines() become string[] get_Hotlines() and List<string> get_HotlinesBySite() becomes string[] get_HotlinesBySite().

为什么即使没有我的询问,文件也被更改了?VS 2012 升级日志说两个文件被更改,但 Reference.cs 不是其中之一.

Why is the file changed even without my asking? The VS 2012 upgrade log said two files were changed but Reference.cs wasn't one of them.

推荐答案

当您添加对 wcf 服务的引用时,您需要将 Collection Type 更改为 Generic List:

When you add reference to wcf service you need to change Collection Type to Generic List:

您也可以更新此设置,只需在解决方案中选择服务引用,右键单击并选择配置服务引用..."

You can also update this settings just select service reference inside your solution, make right mouse click and select "Configure Service Reference..."

这篇关于WCF 代理返回数组而不是列表,即使集合类型 == Generic.List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆