noel0217 发表于 2015-8-13 09:36:57

[WCF实践]1.WCF使用net.tcp寄宿到IIS中

  一、IIS部分


环境:Windows Server 2008 R2


1.安装WAS,如下图所示:





2.网站net.tcp协议绑定,如下图所示:





3.网站启用net.tcp,如下图所示:





二、WCF代码部分

1.DesignCaseService.svc




[*]


<%@ServiceHostLanguage="C#"Debug="true"Service="Web.API.Implementations.DesignCaseService"%>


2.web.config配置示例:




<system.serviceModel>
<services>
<service name="Web.API.Implementations.DesignCaseService" >
<endpoint binding="netTcpBinding" address="" contract="Web.API.Interfaces.IDesignCaseService" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/DesignCaseService"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding portSharingEnabled="true"></binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 非常重要 -->
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false -->
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
  




3.发布服务,框中非常重要,一定要是net.tcp





4.测试服务







三、错误集锦

1.找不到具有绑定 NetTcpBinding 的终结点的与方案 net.tcp 匹配的基址。注册的基址方案是 。



产生原因:网站没有配置net.tcp协议,网站默认只有http协议

解决方案:按照第一部分,配置net.tcp协议

疑问:网站正确配置了net.tcp协议,还报这个错误?

可能原因:端口不对,比如在IIS中配置的net.tcp协议的端口1000,可能在Visul Studio中 右键打开svc文件,会分配另外一个端口,比如2000,这就可能产生这个问题

解决方案:在IIS中打开svc文件



2.已尝试创建到达不支持.Net框架的服务的通道,可能遇到HTTP终结点。需要记录类型"PreambleAck",找到"72"

产生原因:




<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>   

当在默认配置中启用http的元数据时,在发布服务页面会出现以http协议的元数据链接,如下图所示:





我们使用的是net.tcp协议,而在这里显示的却是http协议

解决方案:




<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
  


3.由于目标计算机积极拒绝,无法连接。

查看Net.Tcp Listener Adapter服务是否启动

参考资料:http://www.iyunv.com/Gyoung/archive/2012/12/11/2812555.html

  



来自为知笔记(Wiz)  
页: [1]
查看完整版本: [WCF实践]1.WCF使用net.tcp寄宿到IIS中