码迷,mamicode.com
首页 > 其他好文 > 详细

超简单WCF例子 - 配置文件版

时间:2014-12-08 00:39:48      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   on   

我最欣赏linux的可定制性

so, 配置本身就是一种美

bubuko.com,布布扣
<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <!--第一种元数据发布方式,好像只支持HTTP/HTTPS-->
        <behavior name="CalcServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>

      <service name="ServiceLib.CalcService" behaviorConfiguration="CalcServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://127.0.0.1:8888/Calc"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                  binding="wsHttpBinding"
                  bindingConfiguration=""
                  contract="ServiceLib.ICalcService" />
        <!--第二种元数据发布方式,支持各种协议-->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
配置服务

同样的,代码就可以省略为以下内容

using (ServiceHost host = new ServiceHost(typeof(CalcService)))
{
    host.Opened += (a, b) => Console.WriteLine("服务已开启");
    host.Open();
    Console.Read();
}

而,客户端无须做任何修改

超简单WCF例子 - 配置文件版

标签:style   blog   http   io   ar   color   os   sp   on   

原文地址:http://www.cnblogs.com/hualongbei/p/4150174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!