iblog 5

苹果有iphone,我有iblog

导航

WCF服务寄宿后输出其所有终结点的信息

Posted on 2013-07-28 17:58  cbtech  阅读(253)  评论(1编辑  收藏  举报

配置文件:

  <system.serviceModel>

    <behaviors>
      <serviceBehaviors>
        <behavior name="behavior1">
          <serviceMetadata httpGetEnabled="true" httpGetUrl="wcf10" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>
      <service behaviorConfiguration="behavior1" name="myService.Calculator">
       
        <endpoint address="wcf1" binding="basicHttpBinding" bindingConfiguration=""
          name="endpoint1" contract="myService.ICalculator">
        </endpoint>
       
        <endpoint address="wcf2" binding="wsHttpBinding" bindingConfiguration=""
          name="endpoint2" contract="myService.ICalculator" />
       
        <host>
          <baseAddresses>
            <add baseAddress="http://127.0.0.1:9008" />
          </baseAddresses>
        </host>
                  
      </service>
    </services>
  </system.serviceModel>

输出代码:

ServiceHost host = new ServiceHost(typeof(Calculator));

foreach (ServiceEndpoint p in host.Description.Endpoints)
{
    Console.WriteLine("契约:"+p.Contract.Name);
    Console.WriteLine("绑定:" + p.Binding.Name);
    Console.WriteLine("地址:" + p.Address.Uri.AbsoluteUri);
    Console.WriteLine("\n");
}

运行结果: