为什么WCF返回myObject的[]而不是List< T>像我期待? [英] Why does WCF return myObject[] instead of List<T> like I was expecting?

查看:111
本文介绍了为什么WCF返回myObject的[]而不是List< T>像我期待?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我的WCF方法返回一个列表。在我的客户code,它的返回类型显示为MyObject的[]。我必须要么使用MyObject的[],或IList的,或IEnumerable的...

I am returning a List from my WCF method. In my client code, it's return type shows as MyObject[]. I have to either use MyObject[], or IList, or IEnumerable...

WCFClient myClient = new WCFClient();

    MyObject[] list = myClient.GetMyStuff();
or
    IList<MyObject> list = myClient.GetMyStuff();
or
    IEnumerable<MyObject> list = myClient.GetMyStuff();

所有我做的是采取这一集并将其绑定到一个网格。什么是分配我返回集合最好的对象?

All I am doing is taking this collection and binding it to a grid. What is the best object to assign my returned collection?

推荐答案

您可以指定要使用通用的清单,而不是一个数组通过单击高级按钮,当您添加一个引用,或者你可以右键点击服务引用,然后选择配置来改变它在的地方。

You can specify that you want to use a generic list instead of an array by clicking the advanced button when you add a reference, or you can right click on the service reference and choose configure to change it in place.

原因在于WCF序列化泛型列表作为阵列跨网络发送。该配置只是告诉SvcUtil工具来创建它们转换回到一个泛型列表为了方便您的代理。

The reason is that WCF serializes Generic lists as arrays to send across the wire. The configuration is just telling svcutil to create a proxy that converts them back to a generic list for your convenience.

这篇关于为什么WCF返回myObject的[]而不是List&LT; T&GT;像我期待?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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