我有一个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。
我可以在以下位置添加带元数据的引用
的net.tcp://本地主机:8100 / WCFService / tcpmex
net.pipe://本地主机/ 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端点添加了引用, 我期待:
address = net.tcp:// localhost:8100 / WCFService
和binding =“mexTcpBinding”
服务正在运作,但我想知道,这里发生了什么。 这是什么原因。是由于baseAddress还是给wsHttpBinding一些偏好?
我们对此表示赞赏。
感谢。
答案 0 :(得分:1)
mex
绑定(Metadata EXchange的简称)不是可用于使用您的服务的端点。相反,它仅用于公开有关服务的所有“真实”端点的信息(或元信息) - 请注意您的服务类未实现您在TCP / Pipe端点中定义的IMetadataExchange
合同
在您的情况下,您的服务只有一个“真实”端点 - 使用wsHttpBinding
的端点,它实现了WCFService.IServiceClass
接口。这就是为什么客户端配置中只有一个端点。
现在,如果你有另一个端点使用非元数据绑定(而不是IMetadataExchange
合约),它们也会显示在客户端配置中:
<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>