在后台运行WCF编程应用程序。出现提示后,单击OK按钮激活Web.config中的调试功能。在控制台应用程序窗口中输入一个数字,按下回车键,如下图所示显示一个简单的WCF服务和客户程序。

试试看:一个简单的WCF服务和客户程序#t#
(1) WCF编程:在目录C:BegVCSharp\Chapter35下创建一个新的WCF服务应用程序项目Ch35Ex01
(2)WCF编程: 在解决方案中添加一个控制台应用程序Ch35Ex01Client。
(3) WCF编程:在Build菜单上单击Build Solution选项。
(4)WCF编程: 在Solution Explorer中右击Ch35Ex01Client,选择Add Service Reference选项。
(5)WCF编程; 在Add Service Reference对话框中,单击Discover。
(6)WCF编程: 开始开发Web服务器,加载WCF服务的信息后,展开该引用,查看其细节,如图
(7) WCF编程:单击OK按钮,添加服务引用。
(8)WCF编程: 在Ch35Ex01Client应用程序中修改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();
 - }
 - }
 - }
 
Copyright © 2009-2022 www.wtcwzsj.com 青羊区广皓图文设计工作室(个体工商户) 版权所有 蜀ICP备19037934号