首先,我认为这是一个很有用的插件,如果继续得到改进和增强,我想该插件会被更多开发者使用。对于WCF Service源码的学习,对于我们掌握怎样正确创建WCF Service插件工程是很有帮助的,而且也可从中学到不少编程技巧,例如委托和模板方法。希望大家一起研究下
微软的 WCF Service默认会这样设置,可能如同博文所提到的,WCF Service 的客户端可能是旧版 .NET 1.x 版的环境,也可能是 Java 或其他各种非微软的技术平台,因此 VS 2008 默认选用所有厂商、所有平台都支持的 Array 数组,作为网络传输的类型,而非最新版 .NET 平台特有的 Collection 数据结构。最后,若用户端程序要再更改配置,只要如下图 5 般,在 WCF Service项目里既有的 Reference 上,选择「配置服务引用」即可。#t#
以下为本帖下载示例的代码。我们在服务器端的 WCF Service,提供三个返回类型分别为 List
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- ServiceReference1.ServiceClient prox = new ServiceReference1.ServiceClient();
- /*********** List
***********/ - //string[] list1 = new string[2]; //未改设置前,Server 返回的 List
,Client 只能取得 string 数组 - List
list1 = new List (); - list1 = prox.getListString();
- Response.Write(list1[0] + "
");- Response.Write(list1[1] + "");
- /*********** List<自定义类> ***********/
- List
list2 = new List (); - list2 = prox.getListEmployee();
- Response.Write(list2[0].name + "
");- Response.Write(list2[0].age + "
");- Response.Write(list2[0].oooo + ""); //object 类型
- /*********** Dictionary
,string> ***********/ - Dictionary
, string> dict1 = new Dictionary , string>(); - dict1 = prox.getDictionaryString();
- foreach (KeyValuePair
, string> kvp in dict1) - {
- Response.Write(kvp.Key + ", " + kvp.Value + "
");- }
- }
- }
上一篇:对WCF客户端解释说明
下一篇:对WCF异常解决办法