0
我工作的一個WCF項目 我有2個合同(2個端點)1個服務 ,並用1個合同(1個終點) 我想使1單1個服務ServiceHost爲我的服務。 我可以使2主機2服務,但我只需要1主機。如何承載2個WCF服務1個ServiceHost的
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>
1'ServiceHost'可以託管**一個**服務實現類;但該服務實現可能會實現多個服務合同(接口)... – 2013-04-10 14:08:10
[運行WCF ServiceHost與多個合同]的可能重複(http://stackoverflow.com/questions/334472/run-wcf-servicehost-與-多合同) – qub1n 2014-12-30 12:32:10