我的WCF库中有3个服务合约接口,如下所示:
public interface ServiceContract1{}
public interface ServiceContract2{}
public interface ServiceContract3 : ServiceContract1, ServiceContract2 {}
我也有一个实现ServiceContract3的服务。我可以通过为每个设置不同的合同来拥有不同的端点:
<endpoint address="net.tcp://localhost:5556/ServiceContract1"
binding="netTcpBinding" name="netTcpBinding1"
contract="WcfServiceLibrary.IServiceContract1">
<endpoint address="net.tcp://localhost:5556/ServiceContract2"
binding="netTcpBinding" name="netTcpBinding2"
contract="WcfServiceLibrary.IServiceContract2">
这些端点似乎运行良好,但只有一个mexHttpBinding
端点自动生成。因此,尽管客户端需要使用其中一个端点,但在添加服务引用后它将具有整个类。
我可以为不同的合同设置不同的mexHttpBinding
端点吗?我可以遵循任何方法吗?谢谢你的帮助。
编辑#1:ServiceModel配置
<system.serviceModel>
<services>
<service name="WcfServiceLibrary.Service">
<endpoint address="net.tcp://localhost:5556/Service1"
binding="netTcpBinding" name="netTcpBinding"
contract="WcfServiceLibrary.IServiceContract1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:5556/Service2"
binding="netTcpBinding" name="netTcpBinding"
contract="WcfServiceLibrary.IServiceContract2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
name="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:5555/ConsoleHost" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
我的控制台应用程序中只托管了一项服务:
ServiceHost host = new ServiceHost(typeof(WcfServiceLibrary.Service));
host.Faulted += new EventHandler(Host_Faulted);
// Start listening for messages
host.Open();