0

我正在开发一个 wcf 项目我有 1 个服务和 2 个合同(2 个端点)和 1 个服务和 1 个合同(1 个端点)我想为我的两个服务制作 1 个单一的 ServiceHost。我可以为 2 项服务制作 2 台主机,但我只需要 1 台主机。

ServiceHost myService =
            new ServiceHost(typeof(CustomerOrder),
            new Uri("net.tcp://localhost:9191/T1Flondor_Antal"));

            ServiceHost myService2 =
            new ServiceHost(typeof(ReportServiceCO),
            new Uri("net.tcp://localhost:9191/T1Flondor_Antal"));

和配置:

<system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="T1Flondor_Antal.CustomerOrder"
     behaviorConfiguration="T1Flondor_Antal.MessageBehavior">
        <endpoint address ="net.tcp://localhost:9191/T1Flondor_Antal/Customer"
       binding="netTcpBinding"
       contract="T1Flondor_Antal.ICustomer">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address ="net.tcp://localhost:9191/T1Flondor_Antal/Order"
       binding="netTcpBinding"
       contract="T1Flondor_Antal.IOrder">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex"
       binding="mexTcpBinding"
       contract="IMetadataExchange"/>
      </service>


      <service name="T1Flondor_Antal.ReportServiceCO"
     behaviorConfiguration="T1Flondor_Antal.MessageBehavior">
        <endpoint address ="net.tcp://localhost:9191/T1Flondor_Antal/Report"
       binding="netTcpBinding"
       contract="T1Flondor_Antal.IReport">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>   
        <endpoint address="mex"
       binding="mexTcpBinding"
       contract="IMetadataExchange"/>
      </service>



    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="T1Flondor_Antal.MessageBehavior">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
4

1 回答 1

2

请参阅使用多个合同运行 WCF ServiceHost

您需要在单个对象中实现这两个接口,并在构建 ServiceHost 时使用该对象。

否则:不,你不能那样做。

于 2013-04-10T14:06:28.930 回答