如果我定义一个具有字符串和日期时间属性的 Test 对象,并使用它返回 WCF 中的 IEnumerable(T) 集合
[OperationContract]
IEnumerable<Test> GetTestNotes();
当从客户端调用服务时,我看到它将 IEnumerable 转换为 Test[]:
public Test[] GetTestNotes() {
return base.Channel.GetTestNotes();
}
我能够获取数据。
问题是:使用 IEnumerable(T) 接口而不是具体的 List(T) 有多可靠?
我使用这些 WCF 服务的客户端不仅使用 .NET,还使用 JAVA。
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>
。如果您想更严格地控制客户端界面的外观,最好的选择是在单独的程序集中定义协定,然后在客户端和服务器上引用这些程序集。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)