转:WCF Client 使用配置文件(及其简单的参考,随时要被替换)

原文:http://www.cnblogs.com/baishifeng/archive/2009/07/01/1514827.html

WCF Client 使用配置文件

目前对WCF了解还不是太多,从目前看到的资料,还是觉得使用手写App.config文件是灵活的多,可随时改变EndPoint的配置。

服务端倒容易启动,客户端没有找到打开通道的方式,网上多种方法都不适合,经过查询发现以下办法实现:

Client中配置信息:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>

    <client>
      <endpoint address="net.tcp://192.168.0.2:8210/BaseService" binding="netTcpBinding"
                contract="AGC.Join.Service.IBaseService"   name="myHost"/>
    </client>
  </system.serviceModel>
</configuration>

 

调用服务代码:

ChannelFactory<IBaseService> channel = new ChannelFactory<IBaseService>("myHost");
 IBaseService client = channel.CreateChannel();

 

posted @ 2015-03-08 20:59  阿玛  阅读(204)  评论(0)    收藏  举报