Multiple WCF service of the same service and contract type
Is it possible to host 2 WCF services of the same type and contract on the same AppDomain?
In the configuration below, I am configuring a single service of type Service.SomeService that implements contract ISomeService. what I want to do is be able to host 2 services of this type, of course with different URIs.
<system.serviceModel>
<services>
<service 开发者_运维知识库name="Service.SomeService">
<endpoint address="net.tcp://localhost:8000/SomeService"
binding="netTcpBinding"
contract="Service.ISomeService" />
</service>
</services>
I am also self hosting these services in a windows service.
Thanks.
Yes, a Windows Service can host Multiple WCF Services. Each WCF service must have a unique address however. When you add endpoints to a ServiceHost instance, you must specify a unique address for each end point, which means you must vary atleast one of the scheme (net.tcp, net.pipe, http, etc), domain, port or path.
So basically I should be able to do this by adding multiple endpoints to a service:
<services>
<service name="Service.SomeService">
<endpoint address="net.tcp://localhost:8000/SomeService1"
binding="netTcpBinding"
contract="Service.ISomeService" />
<endpoint address="net.tcp://localhost:8000/SomeService2"
binding="netTcpBinding"
contract="Service.ISomeService" />
</service>
I appears that service type and contract in the configuration file should be unique. But is it possible to instead add 2 services of the same type and contract instead of adding 2 endpoints to the same service?
I appears that service type and contract in the configuration file should be unique.
Why? They don't have to be unique - no way. What has to be unique is the address (the complete one) for the service endpoint - of course, how else would WCF know where to send certain requests?
But is it possible to instead add 2 services of the same type and contract instead of adding 2 endpoints to the same service?
Sure, no problem:
<services>
<service name="Service.SomeService">
<endpoint address="net.tcp://localhost:8000/SomeService1"
binding="netTcpBinding"
contract="Service.ISomeService" />
</service>
<service name="Service.SomeOtherService">
<endpoint address="net.tcp://localhost:8000/SomeService2"
binding="netTcpBinding"
contract="Service.ISomeOtherService" />
</service>
</services>
精彩评论