1

我的 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();
4

0 回答 0