使用github中的示例,设置Windows服务中托管的简单wcf服务可以正常工作。但是,当我添加另一个servicecontract实现时,我无法在同一个baseAddress下托管它,即来自app.config:
<service name="ContractService" behaviorConfiguration="WebServicesBehavior">
<host>
<baseAddresses >
<add baseAddress="baseUri"/>
</baseAddresses>
</host>
<endpoint address="addr1" binding="wsHttpBinding" contract="IContract1"/>
<endpoint address="addr2" binding="wsHttpBinding" contract="IContract2"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
我可以使用这个示例托管2个服务,但是我希望实现在同一个baseAddress和可能的多个端点中托管多个服务契约,但是我对此的搜索解决方案让我陷入困境。
此设置有效:
<services>
<service name="ContractService1" behaviorConfiguration="WebServicesBehavior">
<host>
<baseAddresses >
<add baseAddress="http://localhost:8082/Services/"/>
</baseAddresses>
</host>
<endpoint address="addr1" binding="wsHttpBinding" contract="IContract1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="ContractService2" behaviorConfiguration="WebServicesBehavior">
<host>
<baseAddresses >
<add baseAddress="http://localhost:8083/Services/"/>
</baseAddresses>
</host>
<endpoint address="addr2" binding="wsHttpBinding" contract="IContract2"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
使用ninject的连线与github示例中的相同。
有没有办法使用带有ninject的selfhost wcf实现多个端点?
答案 0 :(得分:1)
通过为同一端口指定不同的baseAddresses,您可以在同一端口上拥有多个服务。
将端点定义中的地址附加到每个服务的基址上,如下所示:
<add baseAddress="http://localhost:8083/Services/addr1"/>
<endpoint address="" binding="wsHttpBinding" contract="IContract1"/>