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

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

问题描述

我正在从我的 WCF 方法返回一个列表.在我的客户端代码中,它的返回类型显示为 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<T>就像我期待的那样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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