[英]Multiple Base Addresses and Multiple Endpoints in WCF
我正在使用两个绑定TCP和HTTP。 我想给两个绑定提供mex数据。 我想要的是mexHttpBinding只暴露HTTP服务,而mexTcpBinding只暴露TCP服务。 或者这是否可能只从HTTP绑定和TCP的eventLogging服务访问stats服务?
例如:
对于TCP,我应该只有
net.tcp://localhost:9001/ABC/mex net.tcp://localhost:9001/ABC/eventLogging
对于HTTP
http://localhost:9002/ABC/stats http://localhost:9002/ABC/mex
当我连接任何基地址(使用WCF测试客户端)时,我能够访问所有服务吗? 就像我使用net.tcp:// localhost:9001 / ABC连接一样,我可以使用HTTP绑定提供的服务。 为什么会这样?
<system.serviceModel>
<services>
<service behaviorConfiguration="ABCServiceBehavior" name="ABC.Data.DataServiceWCF">
<endpoint address="eventLogging" binding="netTcpBinding" contract="ABC.Campaign.IEventLoggingService" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<endpoint address="stats" binding="basicHttpBinding" contract="ABC.Data.IStatsService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9001/ABC" />
<add baseAddress="http://localhost:9002/ABC" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ABCServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我想给两个绑定提供mex数据。 我想要的是mexHttpBinding只暴露HTTP服务,而mexTcpBinding只暴露TCP服务。 或者这是否可能只从HTTP绑定和TCP的eventLogging服务访问stats服务?
好吧,在这种情况下,你需要有两个独立的,不同的服务 - 一个只暴露eventLogging
,另一个只暴露stats
。
当你有两个独立的服务时,你可以通过HTTP公开一个,它的mex只显示那些方法,另一个通过TCP / IP公开它的方法。
<services>
<service name="ABC.Data.DataServiceWCFEventlogging"
behaviorConfiguration="ABCServiceBehavior" >
<endpoint address="eventLogging"
binding="netTcpBinding"
contract="ABC.Campaign.IEventLoggingService" />
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9001/ABC" />
</baseAddresses>
</host>
</service>
<service name="ABC.Data.DataServiceWCFStats"
behaviorConfiguration="ABCServiceBehavior" >
<endpoint address="stats"
binding="basicHttpBinding"
contract="ABC.Data.IStatsService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:9002/ABC" />
</baseAddresses>
</host>
</service>
</services>
如果在同一服务上同时拥有这两种方法,则无法通过http和另一部分通过tcp / ip公开部分方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.