關(guān)于WCF Service相關(guān)介紹
首先,我認為這是一個很有用的插件,如果繼續(xù)得到改進和增強,我想該插件會被更多開發(fā)者使用。對于WCF Service源碼的學(xué)習(xí),對于我們掌握怎樣正確創(chuàng)建WCF Service插件工程是很有幫助的,而且也可從中學(xué)到不少編程技巧,例如委托和模板方法。希望大家一起研究下
微軟的 WCF Service默認會這樣設(shè)置,可能如同博文所提到的,WCF Service 的客戶端可能是舊版 .NET 1.x 版的環(huán)境,也可能是 Java 或其他各種非微軟的技術(shù)平臺,因此 VS 2008 默認選用所有廠商、所有平臺都支持的 Array 數(shù)組,作為網(wǎng)絡(luò)傳輸?shù)念愋?,而非最新?.NET 平臺特有的 Collection 數(shù)據(jù)結(jié)構(gòu)。最后,若用戶端程序要再更改配置,只要如下圖 5 般,在 WCF Service項目里既有的 Reference 上,選擇「配置服務(wù)引用」即可。#t#
以下為本帖下載示例的代碼。我們在服務(wù)器端的 WCF Service,提供三個返回類型分別為 List<string>、List<自定義類>、Dictionary<string,string> 的函數(shù),給 WCF 客戶端 ASP.NET 程序調(diào)用,執(zhí)行結(jié)果:
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- ServiceReference1.ServiceClient prox = new ServiceReference1.ServiceClient();
- /*********** List<string> ***********/
- //string[] list1 = new string[2]; //未改設(shè)置前,Server 返回的 List<string>,Client 只能取得 string 數(shù)組
- List<string> list1 = new List<string>();
- list1 = prox.getListString();
- Response.Write(list1[0] + "<br>");
- Response.Write(list1[1] + "<p>");
- /*********** List<自定義類> ***********/
- List<ServiceReference1.Employee> list2 = new List<ServiceReference1.Employee>();
- list2 = prox.getListEmployee();
- Response.Write(list2[0].name + "<br>");
- Response.Write(list2[0].age + "<br>");
- Response.Write(list2[0].oooo + "<p>"); //object 類型
- /*********** Dictionary<string,string> ***********/
- Dictionary<string, string> dict1 = new Dictionary<string, string>();
- dict1 = prox.getDictionaryString();
- foreach (KeyValuePair<string, string> kvp in dict1)
- {
- Response.Write(kvp.Key + ", " + kvp.Value + "<br>");
- }
- }
- }