WCF 中的多个基址和多个端点
我使用 TCP 和 HTTP 两种绑定。我想提供两个绑定的 mex 数据。 我想要的是 mexHttpBinding 仅公开 HTTP 服务,而 mexTcpBinding 仅公开 TCP 服务。或者我是否可以仅通过 HTTP 绑定访问 stats 服务并通过 TCP 访问 eventLogging 服务?
例如:
对于 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>
I'm using two bindings TCP and HTTP. I want to give mex data on both bindings.
What I want is that the mexHttpBinding only exposes the HTTP services while the mexTcpBinding exposes TCP services only. Or is this possible that I access stats service only from HTTP binding and the eventLogging service from TCP?
For Example:
For TCP I should only have
net.tcp://localhost:9001/ABC/mex net.tcp://localhost:9001/ABC/eventLogging
For HTTP
http://localhost:9002/ABC/stats http://localhost:9002/ABC/mex
When I connect with any of the base address (using the WCF Test Client) I'm able to access all the services? Like when I connect with net.tcp://localhost:9001/ABC I'm able to use the services which are offered on the HTTP binding. Why is that so?
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,在这种情况下,您需要有两个独立的、不同的服务 - 一个仅公开
eventLogging
,另一个仅公开stats
。当您有两个独立的服务时,您可以通过 HTTP 公开一个服务,其 mex 将仅显示这些方法,而另一个通过 TCP/IP 公开并公开其方法。
如果您在同一个服务上使用这两种方法,则无法仅通过 http 公开其中的一部分,并通过 tcp/ip 公开另一部分。
Well, in this case, you need to have two separate, distinct services - one that exposes
eventLogging
only, and another one that exposesstats
only.When you have two separate services, you can expose one over HTTP and its mex will only show those methods, and the other over TCP/IP and expose its methods.
If you have both methods on the same service, there is no way to expose only parts of it over http and another part over tcp/ip.