WCF查找元数据

NND,老了,记忆力都没了。。2个月前学的东西都忘记了。

某app.config

<!-- 部署服务库项目时,必须将配置文件的内容添加到
主机的 app.config 文件中。System.Configuration 不支持库的配置文件。
-->
<system.serviceModel>
<services>
<service name="Tivon.Library.Service1">
<host>
<baseAddresses>
<add baseAddress = "net.tcp://localhost:8732/Design_Time_Addresses/Tivon.Library/Service1/" />
</baseAddresses>
</host>
<endpoint address ="" binding="netTcpBinding" contract="Tivon.Library.IService1"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<!--<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="False"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>-->
</system.serviceModel>

</configuration>

元数据交换终结点提供的元数据不仅描述了契约和操作,还包括关于数据契约、安全性、事务性、可靠性及错误的信息。为了可视化表示正在运行的服务的元数据,MS提供了元数据浏览器工具。

平时我们只写个

<endpoint address ="" binding="netTcpBinding" contract="Tivon.Library.IService1"/>

这样客户端是找不到这个终结点的,所以要加个mex终结点

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>

只有这个中间点也是没用的,还要有个behaviour,如下

<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="False"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>

这样,就能在客户端找到这个终结点了。

原文地址:https://www.cnblogs.com/TivonStone/p/2043694.html