1 部署IIS

1.1 安装WAS

IIS原本是不支持非HTTP协议的服务,为了让IIS支持net.tcp,必须先安装WAS(Windows Process Activation Service),即windows进程激活服务。

打开控制面板--程序和功能--打开或关闭windows功能,安装WAS,如图:

安装完毕后在Services窗口中可以到到如下服务:Windows Process Activation Service;Net.Msmq Listener Adapter;Net.Pipe Listener Adapter;Net.Tcp Listener Adapter;Net.Tcp Port Sharing Service.这几个服务。确定Net.Tcp Listener Adapter 与Net.Tcp Port Sharing Service是否已经启动。

1.2  确定WCF是否启用Non-Http支持
同样是在控件面板中打开这个功能,如图:

1.3 给站点添加net.tcp绑定

在IIS中,选中你的网站,然后在右边的操作菜单栏中单击绑定,会弹出一个“网站绑定”窗口,点击添加,类型选择net.tcp

1.4 启用net.tcp协议

选择你的网站,点击“高级设置”,弹出的的窗体中,在“已启用的协议”一栏中手动添加:net.tcp

2 测试服务

2.1 新建服务

用VS2010新建一个WCF服务,为了简单,我就直接用VS默认生成的作测试了。只有一个GetData方法

下面是配置的Config:

  1. <?xml version="1.0"?>
  2. <configuration>
  3. <system.web>
  4. <compilation debug="true" targetFramework="4.0" />
  5. </system.web>
  6. <system.serviceModel>
  7. <protocolMapping>
  8. <add scheme="tcp" binding="netTcpBinding"/>
  9. </protocolMapping>
  10. <bindings>
  11. <netTcpBinding>
  12. <binding name="netTcpBindConfig"  closeTimeout="00:30:00" portSharingEnabled="true"
  13. openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
  14. transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
  15. hostNameComparisonMode="StrongWildcard" listenBacklog="10">
  16. <readerQuotas maxDepth="2147483647"
  17. maxStringContentLength="2147483647"
  18. maxArrayLength="2147483647"
  19. maxBytesPerRead="2147483647"
  20. maxNameTableCharCount="2147483647" />
  21. <reliableSession ordered="true"  inactivityTimeout="00:01:00" enabled="false" />
  22. <security mode="None">
  23. <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"  />
  24. <message clientCredentialType="Windows"  />
  25. </security>
  26. </binding>
  27. </netTcpBinding>
  28. </bindings>
  29. <services>
  30. <service behaviorConfiguration="MyBehavior" name="WCFService.Service1">
  31. <endpoint address="" binding="netTcpBinding" contract="WCFService.IService1" bindingConfiguration="netTcpBindConfig"></endpoint>
  32. <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint>
  33. </service>
  34. </services>
  35. <behaviors>
  36. <serviceBehaviors>
  37. <behavior name="MyBehavior" >
  38. <serviceMetadata/>
  39. <serviceDebug includeExceptionDetailInFaults="true" />
  40. <dataContractSerializer maxItemsInObjectGraph="6553600"/>
  41. </behavior>
  42. </serviceBehaviors>
  43. </behaviors>
  44. </system.serviceModel>
  45. <system.webServer>
  46. <modules runAllManagedModulesForAllRequests="true"/>
  47. </system.webServer>
  48. </configuration>

2.2 发布服务

将服务发布到IIS,在浏览器中访问服务,如果访问正常就说明服务部署成功,如图:

2.3 测试服务

新建一个控制台项目,测试服务。添加服务

3 遇到的问题

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

这可能是你的网站中没有启用net.tcp协议所到致,也就是少了上面的1.4.

问题2:未找到 URI“net.tcp://gyoung/Service1.svc/mex”的兼容 TransportManager。这可能是因为使用了指向虚拟应用程序外部的绝对地址,或终结点的绑定设置与其他服务或终结点所设置的绑定设置不匹配。 请注意,同一协议的所有绑定在同一应用程序中应具有相同的设置。

这个问题我并没有找到真正的原因,应该是binding设置的原因,我原先的binding配置是:

  1. <binding name="netTcpBindConfig"  closeTimeout="00:30:00" portSharingEnabled="true"
  2. openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
  3. transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
  4. hostNameComparisonMode="StrongWildcard" listenBacklog="10"
  5. maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
  6. maxReceivedMessageSize="2147483647">

这样的话会出现上面的错误,但当我将后面四个节点去掉后,即变成:

  1. <binding name="netTcpBindConfig"  closeTimeout="00:30:00" portSharingEnabled="true"
  2. openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
  3. transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
  4. hostNameComparisonMode="StrongWildcard" listenBacklog="10">

就没有报这个错误了。最后一个问题,园子里哪位大神知道具体原因的,求指导~

问题3有没有必要绑定host地址?

之前我在service节点下有增加host地址

  1. <host>
  2. <baseAddresses>
  3. <add baseAddress="http://localhost:4504"/>
  4. <add baseAddress="net.tcp://localhost:808/Service1.svc"/>
  5. </baseAddresses>
  6. </host>

但我发现这根本不起作用,因不不管我怎么设置,最后我的net.tcp地址都是上面那个,是我设置有错误?

补充一点:

如果你的Silverlight 程序无法调用net.tcp服务,可能是你少了跨域文件:clientaccesspolicy.xml

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <access-policy>
  3. <cross-domain-access>
  4. <policy>
  5. <allow-from http-request-headers="*">
  6. <domain uri="*"/>
  7. </allow-from>
  8. <grant-to>
  9. <resource path="/" include-subpaths="true"/>
  10. <socket-resource port="4502-4530" protocol="tcp" />
  11. </grant-to>
  12. </policy>
  13. </cross-domain-access>
  14. </access-policy>

将clientaccesspolicy.xml放到IIS的根目录:C:\inetpub\wwwroot中,因为SL默认只访问80端口,所以要增加这个文件。

参考:http://www.fengfly.com/plus/view-197313-1.html

WCF开发中将net.tcp协议寄宿到IIS的方法的更多相关文章

  1. WCF:如何将net.tcp协议寄宿到IIS

    1 部署IIS 1.1 安装WAS IIS原本是不支持非HTTP协议的服务,为了让IIS支持net.tcp,必须先安装WAS(Windows Process Activation Service),即 ...

  2. [转]WCF:如何将net.tcp协议寄宿到IIS

    本文转自:http://www.cnblogs.com/Gyoung/archive/2012/12/11/2812555.html 1 部署IIS 1.1 安装WAS IIS原本是不支持非HTTP协 ...

  3. python 全栈开发,Day35(TCP协议 粘包现象 和解决方案)

    一.TCP协议 粘包现象 和解决方案 黏包现象让我们基于tcp先制作一个远程执行命令的程序(命令ls -l ; lllllll ; pwd)执行远程命令的模块 需要用到模块subprocess sub ...

  4. 传输层tcp协议以及scoket套字节方法

    一.传输层 1.传输层的由来: 网络层的IP帮我们区分子网 以太网的Mac帮我们找到主机 所以通过IP和Mac找到了一台特定的主机 如何找到该特定主机的应用程序呢? 答案是通过端口,端口即应用程序与网 ...

  5. C++开发的基于TCP协议的内网聊天工具

    项目相关地址 源码:https://github.com/easonjim/TCPChat bug提交:https://github.com/easonjim/TCPChat/issues

  6. WCF分布式4:客户端访问寄宿在IIS中的WCF服务

    部署过程比较简单,新建一个站点,指向服务的物理路径,设置一个端口.即可. 新建的站点对应一个应用程序池,设置应用程序池中的.NET版本为4.0 写一个测试客户端,访问IIS中的WCF服务,可能会出现, ...

  7. TCP协议的性能评测工具 — Tcpdive开源啦

    Github地址:https://github.com/fastos/tcpdive 为什么要开发Tcpdive 在过去的几年里,随着移动互联网的飞速发展,整个基础网络已经发生了翻天覆地的变化. 用户 ...

  8. TCP协议调试工具TcpEngine V1.3.0使用教程

    简介   这里说的TCP协议调试定义是在开发长连接TCP协议应用时,为了验证代码流程或查找bug,需要与对端交互数据过来,当需要时可以暂停发送:单条发送:跳过发送:正常发送:发送时修改数据等.   T ...

  9. WCF入门教程(四)通过Host代码方式来承载服务 一个WCF使用TCP协议进行通协的例子 jquery ajax调用WCF,采用System.ServiceModel.WebHttpBinding System.ServiceModel.WSHttpBinding协议 学习WCF笔记之二 无废话WCF入门教程一[什么是WCF]

    WCF入门教程(四)通过Host代码方式来承载服务 Posted on 2014-05-15 13:03 停留的风 阅读(7681) 评论(0) 编辑 收藏 WCF入门教程(四)通过Host代码方式来 ...

随机推荐

  1. 3D开机动画

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

  2. 正则js

    匹配中文字符的正则表达式: [\u4e00-\u9fa5] 匹配双字节字符(包括汉字在内):[^\x00-\xff] 匹配空行的正则表达式:\n[\s| ]*\r 匹配HTML标记的正则表达式:/&l ...

  3. Linux 备份 文件夹的权限 然后在其他机器进行恢复

    Study From https://www.cnblogs.com/chenshoubiao/p/4780987.html 用到的命令 getfacl 和 setfacl 备份 getfacl -R ...

  4. ES6学习笔记(一):变量赋值和基本数据类型

    let和const let和const不存在变量提升 变量一定要在声明后使用,否则报错. var a = []; for (var i = 0; i < 10; i++) { a[i] = fu ...

  5. Spring Shell介绍

    最近开发中在下遇到了spring-shell开发工具的项目,现在整理了相关文章,以供大家学习 本博客相关的文章均是在Spring Shell 1.2.0的基础上建立   Spring Shell介绍 ...

  6. SDOI2017 R2泛做

    由于各种原因,在bzoj上我day1的题一题都没过,所以这里就直接贴loj的链接好了. D1T1 龙与地下城 中心极限定理. https://en.wikipedia.org/wiki/Central ...

  7. 【hdu3842】 Machine Works

    http://acm.hdu.edu.cn/showproblem.php?pid=3842 (题目链接) 题意 一个公司使用一个厂房$D$天,希望获利最大.有$n$台机器,每一台可以在第$D_i$天 ...

  8. 适用于vue项目的打印插件(转载)

    出处:https://www.cnblogs.com/lvyueyang/p/9847813.html // 使用时请尽量在nickTick中调用此方法 //打印 export default (re ...

  9. Python基础学习(二)

    前一段时间学习了Python数据类型,语句和函数,目前书写python的新特性,继续练手!!!! 一.切片 之前我们从python的list 或者 tuple中取得元素都是这样写,显然不够灵活 lis ...

  10. Codeforces 468C/469E 易错点

    #include <stdio.h> #include <stdlib.h> typedef long long ll; int main() { ll x=1e17; ll ...