配置文件:blog
<system.serviceModel>ip
<behaviors>
<serviceBehaviors>
<behavior name="behavior1">
<serviceMetadata httpGetEnabled="true" httpGetUrl="wcf10" />
</behavior>
</serviceBehaviors>
</behaviors>get
<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>it
輸出代碼:io
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");
}foreach
運行結果:service