WCF TCP通信方式 通过IIS承载调试

http://www.cnblogs.com/nikymaco/archive/2012/10/08/2715954.html

IIS Express服务器只支持http/https,不支持net.tcp,要改成用local server。
在项目名称上点右键选属性,打开属性页,选"Web":

去掉勾选"Use IIS Express",然后点"Create Virtual Directory"在IIS里建个虚拟目录(如果还没有在IIS里建过的话)。

要确保你的虚拟目录应用程序启用了net.tcp协议。
打开IIS管理器,找到WCFNetTcp这个虚拟目录,点右边高级设置:

已启用的协议中要包含net.tcp

然后你的web.config中的服务的baseAddress要做相应修改,原先的地址是不对的。
services节的配置如下:

XML/HTML code
 
?
1
2
3
4
5
6
7
8
9
10
11
    <services>
      <service name="WCFNetTcp.Service1">
        <endpoint address="" binding="netTcpBinding" contract="WCFNetTcp.IService1" />
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:4502/WCFNetTcp/" />
          </baseAddresses>
        </host>
      </service>
    </services>


上面的端口用的是4502,要确保net.tcp协议在该端口上侦听。
在IIS管理器中检查缺省站点绑定设置:

最后重新编译后就可以在client项目中添加服务引用了。
地址是: net.tcp://localhost:4502/WCFNetTcp/Service1.svc

原文地址:https://www.cnblogs.com/a849788087/p/6867572.html