2

我有一个 WCF 服务,它的配置文件如下所示:

<system.serviceModel>
  <services>
    <service name="WCFService.ServiceClass" behaviorConfiguration="metaDataSupport">
      <host>
        <baseAddresses>
          <add baseAddress="net.pipe://localhost/WCFService"/>
          <add baseAddress="net.tcp://localhost:8100/WCFService"/>
          <add baseAddress="http://localhost:8101/WCFService"/>
        </baseAddresses>
      </host>
      <endpoint address="tcpmex"
                binding="mexTcpBinding"
                contract="IMetadataExchange" />
      <endpoint address="namedpipemex"
                binding="mexNamedPipeBinding"
                contract="IMetadataExchange" />
      <endpoint address=""
                binding="wsHttpBinding"
                contract="WCFService.IServiceClass" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="metaDataSupport">
        <serviceMetadata httpGetEnabled="false" httpGetUrl="" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

我这里有 3 种类型的绑定:NamedPipeBinding、TcpBinding 和 wsHttpBinding。

我可以在以下位置添加带有元数据的引用

  1. net.tcp://localhost:8100/WCFService/tcpmex

  2. net.pipe://localhost/WCFService/namedpipemex

我已经为行为中的服务禁用了 httpGet。

添加了服务引用,但在客户端具有以下配置

<system.serviceModel>
  <bindings>
    <wsDualHttpBinding>
      <binding name="WSHttpBinding_IServiceClass" />
    </wsDualHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:8101/WCFService" binding="wsHttpBinding"
      bindingConfiguration="WSHttpBinding_IServiceClass" contract="TCP.IServiceClass"
      name="WSHttpBinding_IServiceClass">
    </endpoint>
  </client>
</system.serviceModel>

但是由于我使用 TCP Binding 端点添加了一个引用,所以我期望:

地址=net.tcp://localhost:8100/WCFService

和绑定="mexTcpBinding"

该服务正在运行,但我想知道,这里发生了什么。这是什么原因。是由于 baseAddress 还是对 wsHttpBinding 的某些偏好?

想法受到赞赏。

谢谢。

4

1 回答 1

1

The mex binding (short for Metadata EXchange) is not an endpoint which can be used to consume your service. Instead, it's used only used to expose information (or meta information) about all the "real" endpoints of your service - notice that your service class doesn't implement the IMetadataExchange contract which you defined in your TCP/Pipe endpoints.

In your case, your service has only one "real" endpoint - the one using wsHttpBinding, which implements the WCFService.IServiceClass interface. That's why there's only one endpoint in your client configuration.

Now, if you had another endpoint using a non-metadata binding (and not the IMetadataExchange contract), they would show up in the client config as well:

<system.serviceModel>
  <services>
    <service name="WCFService.ServiceClass" behaviorConfiguration="metaDataSupport">
      <host>
        <baseAddresses>
          <add baseAddress="net.pipe://localhost/WCFService"/>
          <add baseAddress="net.tcp://localhost:8100/WCFService"/>
          <add baseAddress="http://localhost:8101/WCFService"/>
        </baseAddresses>
      </host>
      <endpoint address="tcpmex"
                binding="mexTcpBinding"
                contract="IMetadataExchange" />
      <endpoint address="namedpipemex"
                binding="mexNamedPipeBinding"
                contract="IMetadataExchange" />
      <endpoint address=""
                binding="netNamedPipeBinding"
                contract="WCFService.IServiceClass" />
      <endpoint address=""
                binding="netTcpBinding"
                contract="WCFService.IServiceClass" />
      <endpoint address=""
                binding="wsHttpBinding"
                contract="WCFService.IServiceClass" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="metaDataSupport">
        <serviceMetadata httpGetEnabled="false" httpGetUrl="" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>
于 2013-02-10T15:32:18.050 回答