日期:2014-05-18  浏览次数:21137 次

wcf 使用net.tcp方式应该如何设置服务器端配置文件?
弄了两天了,也没搞明白。
下载了一个chartroom 他里面用的就是net.tcp方式,
但是我按照他的那个写法写,也不好用。
这是为什么呢?

------解决方案--------------------
更正一下,估计是你的endpoint的地址中,没有nettcp的连接方式,只有http和mex的连接方式造成的。下面是我重新修改你的app.config后,把原来的

<add baseAddress="http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" /> 
改成
<add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />


全部的配置文件如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- 部署服务库项目时,必须将配置文件的内容添加到 
主机的 app.config 文件中。System.Configuration 不支持库的配置文件。-->
<system.serviceModel>

<services>
<service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior" name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<!--<endpoint address="mex" binding="netTcpBinding" bindingConfiguration="NewBinding0" contract="IMetadataExchange" />-->
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary1.Service1Behavior">
<!-- 为避免泄漏元数据信息, 
请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
<!-- 要接收故障异常详细信息以进行调试, 
请将下值设置为 true。在部署前 
设置为 false 以避免泄漏异常信息-->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>