開發(fā)人員對WCF編程理解講述
在后臺運行WCF編程應(yīng)用程序。出現(xiàn)提示后,單擊OK按鈕激活Web.config中的調(diào)試功能。在控制臺應(yīng)用程序窗口中輸入一個數(shù)字,按下回車鍵,如下圖所示顯示一個簡單的WCF服務(wù)和客戶程序。
試試看:一個簡單的WCF服務(wù)和客戶程序#t#
(1) WCF編程:在目錄C:BegVCSharp\Chapter35下創(chuàng)建一個新的WCF服務(wù)應(yīng)用程序項目Ch35Ex01
(2)WCF編程: 在解決方案中添加一個控制臺應(yīng)用程序Ch35Ex01Client。
(3) WCF編程:在Build菜單上單擊Build Solution選項。
(4)WCF編程: 在Solution Explorer中右擊Ch35Ex01Client,選擇Add Service Reference選項。
(5)WCF編程; 在Add Service Reference對話框中,單擊Discover。
(6)WCF編程: 開始開發(fā)Web服務(wù)器,加載WCF服務(wù)的信息后,展開該引用,查看其細節(jié),如圖
(7) WCF編程:單擊OK按鈕,添加服務(wù)引用。
(8)WCF編程: 在Ch35Ex01Client應(yīng)用程序中修改Pragram.cs中的代碼,如下所示:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Ch35Ex01Client.ServiceReference1;
- namespace Ch35Ex01Client
- {
- class Program
- {
- static void Main(string[] args)
- {
- string numericInput = null;
- int intParam;
- do
- {
- Console.WriteLine(
- "Enter an integer and press enter to call the WCF service.");
- numericInput = Console.ReadLine();
- }
- while (!int.TryParse(numericInput, out intParam));
- Service1Client client = new Service1Client();
- Console.WriteLine(client.GetData(intParam));
- Console.WriteLine("Press an key to exit.");
- Console.ReadKey();
- }
- }
- }