0

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>
Stefan Flondor
  • 359
  • 1
  • 6
  • 13
  • 1
    1 `ServiceHost` can host exactly **one** service implementation class; but that service implementation could potentially implement more than one service contract (interface).... – marc_s Apr 10 '13 at 14:08
  • possible duplicate of [Run WCF ServiceHost with multiple contracts](http://stackoverflow.com/questions/334472/run-wcf-servicehost-with-multiple-contracts) – Tomas Kubes Dec 30 '14 at 12:32

1 Answers1

2

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.

Community
  • 1
  • 1
Vincent Vancalbergh
  • 3,267
  • 2
  • 22
  • 25