IEnumerable的< T>作为WCF方法的返回类型 [英] IEnumerable<T> as return type for WCF methods

查看:105
本文介绍了IEnumerable的< T>作为WCF方法的返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我定义一个Test对象,使用string和Datetime属性并使用它来返回WCF中的IEnumerable(T)集合

If i define a Test object, with string and Datetime properties and use it to return IEnumerable(T) collection in WCF

[OperationContract]
IEnumerable<Test> GetTestNotes();

当从客户端调用服务时,我看到它正在将IEnumerable转换为Test [] :

and when calling the service from the client, I see that it is converting the IEnumerable to Test[]:

public Test[] GetTestNotes() {
    return base.Channel.GetTestNotes();
} 

我能够获得数据。

问题是:使用IEnumerable(T)接口而不是具体的List(T)有多可靠?

Question is: How reliable is it to use IEnumerable(T) interface rather than concrete, List(T)?

我的客户端使用这些WCF服务不仅在.NET中,而且在JAVA中。

My clients that consume these WCF services are not only in .NET but also in JAVA.

推荐答案

如果您正在使用Visual Studio生成的服务引用,那么可以选择用于集合的类型。右键单击Service References下的服务,然后选择 Configure Service Reference… 。您应该看到以下选项:

If you're using the Visual Studio generated service references, you can pick what type is used for collections. Right-click on the service under Service References and select Configure Service Reference…. You should see these options:

但是,这仍然不允许您选择 IEnumerable< T> 。如果您希望更严格地控​​制客户端界面的外观,最好的办法是在单独的程序集中定义合同,然后在客户端和服务器上引用这些程序集。

However, this still won't allow you to select IEnumerable<T>. If you want tighter control over what the client interface looks like, your best bet is to define the contracts in a separate assembly and then reference those assemblies on both the client and server.

这篇关于IEnumerable的&LT; T&GT;作为WCF方法的返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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