WCF 中的多个基址和多个端点

发布于 2024-08-25 00:08:29 字数 1814 浏览 3 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹苦笑 2024-09-01 00:08:29

我想提供两者的墨西哥数据
绑定。我想要的是
mexHttpBinding 仅公开 HTTP
服务,而 mexTcpBinding
仅公开 TCP 服务。或者是这个
我可能访问统计服务
仅来自 HTTP 绑定和
来自 TCP 的事件记录服务?

好吧,在这种情况下,您需要有两个独立的、不同的服务 - 一个仅公开 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 公开另一部分。

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?

Well, in this case, you need to have two separate, distinct services - one that exposes eventLogging only, and another one that exposes stats 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.

<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>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文