開(kāi)發(fā)人員對(duì)WCF編程理解講述
在后臺(tái)運(yùn)行WCF編程應(yīng)用程序。出現(xiàn)提示后,單擊OK按鈕激活Web.config中的調(diào)試功能。在控制臺(tái)應(yīng)用程序窗口中輸入一個(gè)數(shù)字,按下回車(chē)鍵,如下圖所示顯示一個(gè)簡(jiǎn)單的WCF服務(wù)和客戶(hù)程序。
試試看:一個(gè)簡(jiǎn)單的WCF服務(wù)和客戶(hù)程序#t#
(1) WCF編程:在目錄C:BegVCSharp\Chapter35下創(chuàng)建一個(gè)新的WCF服務(wù)應(yīng)用程序項(xiàng)目Ch35Ex01
(2)WCF編程: 在解決方案中添加一個(gè)控制臺(tái)應(yīng)用程序Ch35Ex01Client。
(3) WCF編程:在Build菜單上單擊Build Solution選項(xiàng)。
(4)WCF編程: 在Solution Explorer中右擊Ch35Ex01Client,選擇Add Service Reference選項(xiàng)。
(5)WCF編程; 在A(yíng)dd Service Reference對(duì)話(huà)框中,單擊Discover。
(6)WCF編程: 開(kāi)始開(kāi)發(fā)Web服務(wù)器,加載WCF服務(wù)的信息后,展開(kāi)該引用,查看其細(xì)節(jié),如圖
(7) WCF編程:?jiǎn)螕鬙K按鈕,添加服務(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();
- }
- }
- }