多基址和WCF多个端点 [英] Multiple Base Addresses and Multiple Endpoints in WCF

查看:272
本文介绍了多基址和WCF多个端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用两个绑定TCP和HTTP。我想给 MEX 在两个​​绑定数据。 我想的是,mexHttpBinding只公开了HTTP服务,而mexTcpBinding只公开TCP服务。或者说,我是从HTTP绑定,并在 EVENTLOGGING 从TCP服务访问的统计信息服务仅是这可能吗?

例如:

  • 有关TCP我应该只有

     的net.tcp://本地主机:9001 / ABC / MEX
    的net.tcp://本地主机:9001 / ABC / EVENTLOGGING
     

  • 有关HTTP

     的http://本地主机:9002 / ABC /统计
    HTTP://本地主机:9002 / ABC / MEX
     

当我跟任何一个基址(使用WCF测试客户端)的我能够访问所有的服务?当我跟喜欢的的net.tcp://本地主机:9001 / ABC 我能使用它们提供的HTTP绑定的服务。为什么会这样?

 < system.serviceModel>
  <服务>
    <服务behaviorConfiguration =ABCServiceBehaviorNAME =ABC.Data.DataServiceWCF>
      <端点地址=EVENTLOGGING绑定=NetTcpBinding的合同=ABC.Campaign.IEventLoggingService/>
      <端点地址=MEX绑定=mexTcpBindingbindingConfiguration =合同=IMetadataExchange接口/>
      <端点地址=统计绑定=basicHttpBinding的合同=ABC.Data.IStatsService/>
      <端点地址=MEX绑定=mexHttpBinding合同=IMetadataExchange接口/>
      <主机>
        < baseAddresses>
          <新增baseAddress =的net.tcp://本地主机:9001 / ABC/>
          <新增baseAddress =HTTP://本地主机:9002 / ABC/>
        < / baseAddresses>
      < /主机>
    < /服务>
  < /服务>
  <行为>
    < serviceBehaviors>
      <行为NAME =ABCServiceBehavior>
        < serviceMetadata httpGetEnabled =FALSE/>
        < serviceDebug includeExceptionDetailInFaults =真/>
      < /行为>
    < / serviceBehaviors>
  < /行为>
< /system.serviceModel>
 

解决方案
  

我想给两个MEX数据   绑定。我想的是,   mexHttpBinding仅公开HTTP   而mexTcpBinding服务   公开只有TCP服务。或者是这样的   可能是我访问统计服务   仅从HTTP绑定和   从TCP EVENTLOGGING服务?

那么,在这种情况下,你需要有两个独立的,不同的服务 - 一个公开 EVENTLOGGING 只,另有一暴露统计只。

当你有两个不同的服务,您可以公开一个通过HTTP和MEX将只显示那些方法,以及其他通过TCP / IP和揭露它的方法。

 <服务>
  <服务名称=ABC.Data.DataServiceWCFEventlogging
           behaviorConfiguration =ABCServiceBehavior>
    <端点地址=EVENTLOGGING
              绑定=NetTcpBinding的
              合同=ABC.Campaign.IEventLoggingService/>
    <端点地址=MEX
              绑定=mexTcpBinding
              合同=IMetadataExchange接口/>
    <主机>
       < baseAddresses>
         <新增baseAddress =的net.tcp://本地主机:9001 / ABC/>
       < / baseAddresses>
     < /主机>
  < /服务>
  <服务名称=ABC.Data.DataServiceWCFStats
           behaviorConfiguration =ABCServiceBehavior>
     <端点地址=统计
               绑定=basicHttpBinding的
               合同=ABC.Data.IStatsService/>
     <端点地址=MEX
               绑定=mexHttpBinding
               合同=IMetadataExchange接口/>
     <主机>
        < baseAddresses>
           <新增baseAddress =HTTP://本地主机:9002 / ABC/>
        < / baseAddresses>
     < /主机>
  < /服务>
< /服务>
 

如果你有相同的服务这两种方法,也没有办法揭穿它只有部分通过HTTP和另一部分通过TCP / IP。

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>

解决方案

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.

这篇关于多基址和WCF多个端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆