执行此操作的最简单方法(AFAIK)是创建一个自定义的ServiceHost/ServiceHostFactory对,并将DiscoveryEndpoint添加到构造函数/ OnOpening()方法中的ServiceHost。
如果您在IIS中托管服务,则需要更新.svc文件并将Factory属性指向新的ServiceHostFactory,或者如果您已使用WCF 4.0中的新服务激活功能,则需要更新配置文件:
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceDiscovery>
<announcementEndpoints>
<endpoint
name="MyAnnouncementEndpoint"
kind="announcementEndpoint"
address="net.tcp://localhost/My.ServiceLocator/DiscoveryProxy.svc"
bindingConfiguration ="NetTcpBindingConfiguration"
binding="netTcpBinding"/>
</announcementEndpoints>
</serviceDiscovery>
</behavior>
</serviceBehaviors>
</behaviors>
这样,所有的服务都将使用这个默认的行为,即使你不”的那些:
<configuration><system.serviceModel><serviceHostingEnvironment><serviceActivations>... </...
我也在考虑ServiceHostFactory,但也许有一种方法可以强制默认服务主机为自定义服务主机。 – R4cOON 2011-05-10 06:47:53