IIS部署WCF
2015-11-24 16:40
337 查看
1 部署IIS
1.1 安装WAS
IIS原本是不支持非HTTP协议的服务,为了让IIS支持net.tcp,必须先安装WAS(Windows Process Activation Service),即windows进程激活服务。打开控制面板--程序和功能--打开或关闭windows功能,安装WAS,如图:
View Code
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <protocolMapping> <add scheme="tcp" binding="netTcpBinding"/> </protocolMapping> <bindings> <netTcpBinding> <binding name="netTcpBindConfig" closeTimeout="00:30:00" portSharingEnabled="true" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <reliableSession ordered="true" inactivityTimeout="00:01:00" enabled="false" /> <security mode="None"> <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> <message clientCredentialType="Windows" /> </security> </binding> </netTcpBinding> </bindings> <services> <service behaviorConfiguration="MyBehavior" name="WCFService.Service1"> <endpoint address="" binding="netTcpBinding" contract="WCFService.IService1" bindingConfiguration="netTcpBindConfig"></endpoint> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MyBehavior" > <serviceMetadata/> <serviceDebug includeExceptionDetailInFaults="true" /> <dataContractSerializer maxItemsInObjectGraph="6553600"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </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配置是:
<binding name="netTcpBindConfig" closeTimeout="00:30:00" portSharingEnabled="true" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647">
这样的话会出现上面的错误,但当我将后面四个节点去掉后,即变成:
<binding name="netTcpBindConfig" closeTimeout="00:30:00" portSharingEnabled="true" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10">
就没有报这个错误了。最后一个问题,园子里哪位大神知道具体原因的,求指导~
问题3:有没有必要绑定host地址?
之前我在service节点下有增加host地址
<host> <baseAddresses> <add baseAddress="http://localhost:4504"/> <add baseAddress="net.tcp://localhost:808/Service1.svc"/> </baseAddresses> </host>
但我发现这根本不起作用,因不不管我怎么设置,最后我的net.tcp地址都是上面那个,是我设置有错误?
补充一点:
如果你的Silverlight 程序无法调用net.tcp服务,可能是你少了跨域文件:clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8" ?> <access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> <socket-resource port="4502-4530" protocol="tcp" /> </grant-to> </policy> </cross-domain-access> </access-policy>
将clientaccesspolicy.xml放到IIS的根目录:C:\inetpub\wwwroot中,因为SL默认只访问80端口,所以要增加这个文件。
参考:http://www.cnblogs.com/chenkai/archive/2011/03/14/1984104.html
如果我的文章对你有帮助,就点一下推荐吧.(*^__^*)
相关文章推荐
- 模板模式
- 数据类型/强制类型转换 和运算符---标识符规则/关键字 a++和++a区别
- jquery设置个滚动条位置,使页面回到顶端
- 基于注释的Spring cache 缓存介绍
- 通过修改host文件访问谷歌
- 二叉树遍历
- 转:makefile里面引用shell注意
- hadoop 平台搭建
- UIImageView 图片填充,按比例,平铺
- 1. Magento2 --- (1) theme ---create a theme
- ehcache在windows下使用RMI同步时出现的问题
- 对于字符串的单个打印、部分打印及全部打印问题
- No1-【原】hexo系列文章之微博秀
- CGBitmapContextCreate函数
- jquery利用拖拽方式在图片上添加热链接
- jquery瀑布流
- 如何使用java的正则表达式提取html标签?
- 【codevs1422】河城荷取 二分+dinic
- 在 Windows 上安装Rabbit MQ 指南
- IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)