配置文件:
<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");
}
运行结果: