Multiple Base Addresses and Multiple Endpoints in WCF

纵然是瞬间 提交于 2019-12-09 23:46:05

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/2399865/multiple-base-addresses-and-multiple-endpoints-in-wcf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!