对WCF客户端解释说明

开发 后端
使用WCF客户端,开发人员可以随意的构建跨平台、安全、可靠和支持事务处理的企业级互联应用解决方案。大大的提高了工作效率。

WCF客户端包括许多新的和改进的用于提高工作效率的功能。IDE 还进行了重新设计,从而向开发人员提供对.NET Framework 组件的直接访问。

[注:Method、Operation 中文都叫做「方法」,但前者是存在 OO 中的类,不存在网络上;后者存在于 Service 中,公开在网络上可供其他程序调用。WCF、Data Services 和 RIA Services 中公开在网络上的函数和方法,都可称作 Operation。#t#

关于这点,小弟我查了微软 MCTS 认证 WCF 3.5 的官方用书 [10]、O'Reilly 的书籍 [11],都未提到如何解决,书中只提到 .NET collections 的 metadata,以 WSDL 在网络上传输时,会以「数组 (array)」的格式呈现。

Because .NET collections are .NET-specific, WCF cannot expose them in the service metadata, yet because they are so useful, WCF offers dedicated marshaling rules for collections.

Whenever you define a service operation that uses the collection interfaces IEnumerable<T>, IList<T>, or ICollection<T>, the specific collection-type information gets lost in the metadata (WSDL) export, so in terms of how collection types are sent across the wire, they all are represented as arrays, the resulting metadata always uses an array.

开发WCF客户端 时,若 VS 2008 都用默认配置,则当 WCF 的服务器端函数 (Operation) 的返回类型为 List<string> 时,实际返回的类型为 string[] 数组,因此客户端若仍用 List<string> 的变量去接收和赋值时,在编译时期,即会发生下图 1 的转型错误:

WCF 客户端程序「添加服务引用 (Add Service Reference)」的设置即可处理此种需求。做法如下:

请参阅本帖。当我们的WCF客户端程序,要引用网络上既有的 WCF 服务契约时,我们会如下图 2 般,添加一个 service proxy reference。

 


责任编辑:chenqingxiang 来源: 计世网
相关推荐

2009-11-05 13:00:25

WCF客户端

2009-12-22 18:18:11

WCF客户端编程

2010-02-25 16:20:02

WCF客户端

2009-12-08 16:47:06

WCF IP

2009-12-22 10:29:59

WCF客户端处理

2009-12-08 16:15:13

WCF服务

2010-02-24 16:39:27

WCF客户端处理

2010-02-23 09:58:21

WCF客户端验证

2009-12-21 15:53:56

WCF获取客户端IP

2010-02-22 11:10:17

WCF获取客户端IP

2009-11-09 15:49:01

WCF异步调用

2009-11-05 13:08:44

WCF客户端配置

2011-09-09 09:44:23

WCF

2009-12-07 17:46:52

WCF框架

2009-12-07 17:28:55

WCF数据

2009-12-21 10:19:05

Silverlight

2010-02-24 16:17:09

WCF获取客户端IP

2010-02-23 15:12:25

WCF客户端

2009-12-08 09:33:53

WCF服务

2009-12-21 10:09:26

WCF创建客户端服务对
点赞
收藏

51CTO技术栈公众号