WCF:在异步合同我返回列表< T>但我收到客户端的数组 [英] WCF: in async contract I return List<T> but I receive in client an array

查看:99
本文介绍了WCF:在异步合同我返回列表< T>但我收到客户端的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WCF服务合同我已经宣布了ASYN方法返回一个列表,但是当我的客户,我收到来自该方法的返回时,我收到一个数组。我的合同是以下内容:

In my WCF service contract I have declared an asyn method that return a List, but when in my client I receive the return from the method, I receive an array. My contract is the following:

[OperationContract(AsyncPattern = true)]
IAsyncResult BeginGetUsers(Paramusers paramUserParameters, AsyncCallback callback, object state);
List<Users> EndGetUsers(IAsyncResult result);

在我的客户,我有以下code:

In my client I have the following code:

Task<List<Users>> task = Task<List<Users>>.Factory.FromAsync(_proxy.Proxy.BeginGetUsers, _proxy.Proxy.EndGetUsers, myParameters,  null);
List<Users> myUsers = await task;

在客户端,我收到一个错误在FromAsync方法的第二个参数,因为它说,EndGetUsers方法返回一个数组,而不是一个列表。

In the client, I receive an error in the second parameter of FromAsync method, because it says that the EndGetUsers method returns an array, not a list.

我尝试使用用户的数组,并能正常工作,但我想从异步方法,而不是一个阵列接收名单。这可能吗?

I try to use an array of users and works fine, but I would like to receive the list from the async method, not an array. is it possible?

感谢。
Daimroc。

Thanks. Daimroc.

推荐答案

当您创建客户端代理,指定要集合重新presented的名单,而不是阵列 - 使用添加服务引用的时候对话框中,选择高级按钮,然后选择 System.Collections.Generic.List 在集合类型下拉列表中。

When you create your client proxy, specify that you want collections to be represented as lists instead of arrays - when using the "Add Service Reference" dialog, choose the "Advanced" button, then select System.Collections.Generic.List in the collection type drop-down list.

如果您使用 SvcUtil工具,您可以使用 / collectionType (或 / CT )参数指定要使用的集合类型:

If you use svcutil, you can use the /collectionType (or /ct) parameter to specify the type of collections to use:

svcutil http://the.service.com/service.svc /ct:System.Collections.Generic.List`1

这篇关于WCF:在异步合同我返回列表&LT; T&GT;但我收到客户端的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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