从WCF服务公开DataTable,所有泛型列表均转换为数组 [英] Expose DataTable from WCF service, all Generic lists convert to arrays

查看:71
本文介绍了从WCF服务公开DataTable,所有泛型列表均转换为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我向.Net 3.5 WCF Web服务添加了一种方法,该方法返回一个DataTable. Web服务中的其他方法返回通用列表和/或将通用列表作为参数.

当我更新对我的客户端应用程序中更改后的Web服务的引用时,所有用作参数的通用列表或Web服务中所有方法的返回类型都将转换为数组. >

在服务参考设置中,我选择了"System.Collections.Generic.List".显然,当Web服务返回数据表时,此设置无效吗?

有什么方法可以防止这种情况发生吗?

复制步骤:

  1. 使用返回通用列表和/或将通用列表作为参数的方法创建Web服务.
  2. 在客户端应用程序中,引用Web服务并选择"System.Collections.Generic.List".作为收集类型.确认返回类型/参数类型是通用列表.
  3. 向Web服务中添加一个返回DataTable的方法.
  4. 在客户端应用程序中更新服务引用.请注意,所有通用列表(无论是作为返回类型还是方法参数)都已更改为数组.即使收集类型服务参考设置保持为"System.Collections.Generic.List",也会发生这种情况.

 


Tom Regan

解决方案

我意识到所有集合都被转换为数组以进行传输.那不是问题.我的问题出在客户参考中.

客户端可以设置集合类型,然后选择将集合作为通用列表进行处理.问题在于,当引用的Web服务公开数据表时,此操作将失败.即使我在客户端中将收集类型设置为通用 列表中,Web服务参考将所有集合打包为数组.

仅当Web服务包含返回DataTable的方法时,才会发生这种情况.如果删除该方法,我的通用列表的收集类型将在客户端中按预期工作.

您知道为什么无法从公开DataTable的Web服务中检索通用列表吗?


I added a method to a .Net 3.5 WCF web service that returns a DataTable.  Other methods in the web service return Generic lists and/or take Generic lists as parameters. 

When I update my reference to the altered web service from my client application all generic lists used as parameters or return types from all methods in the web service are converted to arrays. 

In my service reference settings I have selected "System.Collections.Generic.List."  Apparently this setting has no effect when a web service returns a DataTable?

Is there any way to prevent this from occuring?

Steps to reproduce:

  1. Create a web service with methods that return Generic lists and/or take Generic lists as parameters.
  2. In a client application reference the web service and select "System.Collections.Generic.List" as the collection type.  Verify that return types/parameter types are generic lists.
  3. Add a method to the web service that returns a DataTable. 
  4. In a client application update the service reference. Note that all Generic lists (either as return types or method parameters) have changed to arrays.  This occurs even though the collection type service reference setting remains as "System.Collections.Generic.List".

 


Tom Regan

解决方案

I realize that all collections are converted to arrays for transmission.  That is not the issue.  My problem is in the client reference.

The client can set a collection type and choose to treat collections as generic lists.  The problem is that this fails when the referenced web service exposes a DataTable.  Even though I set my collection type in the client to generic lists, the web service reference packages all collections as arrays.

This only happens when the web service contains a method that returns a DataTable.  If I remove that method my collection type of generic lists works as expected in the client.

Do you know why it is not possible to retrieve generic lists from a web service that exposes a DataTable? 


这篇关于从WCF服务公开DataTable,所有泛型列表均转换为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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