为什么将WCF方法的返回类型从通用集合更改为数组? [英] Why would a WCF method's return type be changed from a generic collection to an array?

查看:113
本文介绍了为什么将WCF方法的返回类型从通用集合更改为数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务方法,我为返回类型编写了WCF服务方法。

I have a WCF service method which I have written for return type as collection type.

但是,如果我生成一个代理类并从客户端使用该方法,方法返回类型从集合更改为数组。

But if I generate a proxy class and consume the method from the client the methods return type is changed from a collection to an array.

为什么会这样?

推荐答案

您需要告诉 svcutil 生成所需类型的类型。您可以通过在svcutil命令中添加此开关来实现此目的:

You need to tell svcutil to generate the types as whatever generic type you want. You do this by adding this switch to the svcutil command:

svcutil ..blah... /ct:System.Collections.ObjectModel.Collection`1

/ ct / collectionType 的缩写。在这种情况下,我指定了 Collection< T> ,但您可以很容易使用 System.Collections.Generic.List< T>

The /ct is short for /collectionType. In this case I specified Collection<T> but you could have just as easily used System.Collections.Generic.List<T>.

这篇关于为什么将WCF方法的返回类型从通用集合更改为数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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