简体   繁体   中英

how to host 2 wcf services in 1 servicehost

i'm working on a wcf project i have 1 service with 2 contracts (2 endpoints) and 1 service with 1 contract (1 endpoint) i want to make 1 single ServiceHost for both my services. i can make 2 host for 2 services but i need only 1 host.

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"));

and the config:

<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>

See Run WCF ServiceHost with multiple contracts :

You need to implement both interfaces in a single object and use that object when constructing your ServiceHost.

Otherwise: No, you can't do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM