Reputation: 369
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>
Upvotes: 0
Views: 4209
Reputation: 3327
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.
Upvotes: 2