入门代码教程第五节 如何:配置客户端

如何:配置基本 Windows Communication Foundation 客户端

配置客户端包括指定客户端用于访问服务的终结点。 每个终结点都有一个地址、一个绑定和一个协定,所有这些元素都必须在配置客户端的过程中指定。

在过程后面的示例中提供了为客户端生成的配置文件的内容。

配置 Windows Communication Foundation 客户端

在 Visual Studio 中,将在前一过程如何:创建 Windows Communication Foundation 客户端中生成的 App.config 配置文件添加到客户端项目中。 在“解决方案资源管理器”中右击该客户端,选择“添加现有项”,然后从 C:\Documents and Settings\<用户名>\Documents\Visual Studio 2008\Projects\Service\Client\bin 目录中选择 App.config 配置文件 (之所以命名为 App.config 文件,是因为在使用 Svcutil.exe 工具生成此文件时使用了 /config:app.config 开关)。

打开生成的配置文件。 Svcutil.exe 会为绑定上的每一项设置都生成值。 下面的示例显示了生成的配置文件。 请在 <system.serviceModel> 节下查找 <endpoint> 元素。 下面的配置文件是所生成的文件的简化版本。

 

<? xml version = " 1.0 "  encoding = " utf-8 " ?>
< configuration >
  
< system.serviceModel >
    
< bindings >
      
< wsHttpBinding >
        
< binding name = " WSHttpBinding_ICalculator " >
        
</ binding >
      
</ wsHttpBinding >
    
</ bindings >
    
< client >
      
< endpoint
           address
= " http://localhost:8000/ServiceModelSamples/Service/CalculatorService "
           binding
= " wsHttpBinding "
           bindingConfiguration
= " WSHttpBinding_ICalculator "
           contract
= " Microsoft.ServiceModel.Samples.ICalculator "
           name
= " WSHttpBinding_ICalculator " >
      
</ endpoint >
    
</ client >
  
</ system.serviceModel >
</ configuration >  

 

此示例配置的终结点可供客户端在访问位于以下地址的服务时使用:http://localhost:8000/ServiceModelSamples/service

终结点元素指定 Microsoft.ServiceModel.Samples.ICalculator 协定将用于通过系统提供的 WsHttpBinding 配置的通信。 此绑定指定 HTTP 作为传输协议、可互操作安全性以及其他配置详细信息。

创建和配置了客户端后,下一步是使用客户端来访问服务。

转载于:https://www.cnblogs.com/tomkillua/archive/2008/09/25/1298649.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值