采用nettcp绑定的wcf宿主到iis7

 

采用nettcp绑定的wcf宿主到iis7

也许事情太杂了记忆力明显下降,做过的东西很容易忘记。上次成功将采用nettcp绑定方式的wcf部署到iis7,重新来做已经忘得差不多了。

重新在网上搜索相关资料,进行记录以备再用。
一、准备:首先iis必须是7.0或更高,同时需要安装需要在“打开或关闭Windows功能”中安装Microsoft .NET Framework 3.5.1中的Windows Communication Foundation HTTP Activation、Windows Communication Foundation Non-HTTP Activation和Web管理工具-IIS6管理兼容性-IIS元数据库和IIS6配置兼容性这三个功能;(我的系统是win7旗舰版)

在iis中,我干脆把所有的服务都安装了。

二、配置网站支持nettcp协议
防火墙需要为nettcp服务开洞,要允许端口:4502-4534通过

4502:*
 下面就可以创建你的网站虚拟目录并确定启用nettcp协议

(3)wcf在访问的时候存在跨域问题,在wwwroot文件夹即网站跟目录下放置跨域访问文件和策略文件clientaccesspolicy.xml、crossdomain.xml。文件内容如下:
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>
crossdomain.xml内容:

<?xml version="1.0"?>
<cross-domain-policy>
 <allow-access-from domain="*"/>
</cross-domain-policy>

三、其他注意问题:

    4.在向Silverlight项目中添加服务引用的时候有时会出现Could not load file or assembly 'System.ServiceModel.Activation.HttpModule’ from assembly…的错误,则需要在命令行中运行C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis.exe -iru重新安装ASP.NET 4.0

5.注意WAS的启动

Windows (Process) Activation Service (WAS)作为 IIS7.0 特有的新增功能,和以前IIS 6.0的功能相比更加强大,因为它提供并支持除HTTP之外的更多协议,比如TCP方式和Pipe(管道)方式。利用WAS作为WCF(Windows Communication Foundation)的宿主,我们能充分利用WAS的很多优点,因为我们再也不用为非HTTP方式的WCF Service单独编写宿主程序了。而WAS本身的特点,也让我们的服务端程序能享受到只有以往的HTTP方式的WCF Service才能拥有的很多特性。
WAS在Windows Vista/7/2008/R2中,其实是由一个单独的Windows Service来实现的 在Windows服务里头可以找到一个Windows Service,就叫做"Windows Process Activation Service"。由此看来,WAS的进程和IIS进程在物理上是隔离开的,能为我们提供一个灵活、稳定的WCF Service宿主环境。WAS内部的工作机制,大致和ASMX WebService类似。
IIS 7上 引入了以下三组网络监听器(Listener)和监听适配器(Adapter),实现了基于TCP、Named Pipes和MSMQ的网络监听。分别是:
TCPListener|TCP Listener Adapter
NamedPipes Listener|Named Pipes Listener Adapter
MSMQ Listener|MSMQ Listener Adapter
在IIS 7的结构如下
 

由于IIS 7提供了基于非HTTP网络协议的监听支持,那么就意味着当我们当我们通过IIS进行WCF服务寄宿(Hosting)的时候,可以采用非HTTP的通信方式。其中的TCPListener|TCP Listener Adapter 依赖于服务NetTcpPortSharing,为net.tcp绑定提供tcp的端口共享,具体可参看启用WCF NetTcpBinding的共享端口。

文章来自学IT网:http://www.xueit.com/html/2010-01-25/21-982353359406.html

一些参考网址:http://archive.cnblogs.com/a/1883612/
http://files.cnblogs.com/dhuxin/WCF.NetTCP%e7%bb%91%e5%ae%9a%e9%85%8d%e7%bd%ae%e8%af%b4%e6%98%8e.pdf
http://www.cnblogs.com/chocstarfish/archive/2010/06/26/1765568.html
http://www.singingeels.com/Articles/Duplex_WCF_Services_Hosted_in_IIS_Using_NetTcp.aspx
http://www.cnblogs.com/cubean/archive/2009/08/28/1555223.html
http://archive.cnblogs.com/a/1959748/
四、1、我的wcfweb配置文件

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="tcpBindingNoSecurity"  receiveTimeout="24.00:00:00">
          <reliableSession inactivityTimeout="24.00:00:00" />
          <!--每次最大发送数据流大小-->
          <readerQuotas maxArrayLength="2147483647" />
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
     <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
          <!--原来为FALSE-->
          <!--这里添加行开始修改默认的可序列化的集合长度为默认值的100倍6553600-->
          <dataContractSerializer maxItemsInObjectGraph="6553600"/>
          <!--这里添加行结束-->
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--这里开始添加-->
    <services>
      <service name="ActService.Service">
        <endpoint address="net.tcp://11.1.21.0:4502/Service/Service.svc"
            binding="netTcpBinding" bindingConfiguration="tcpBindingNoSecurity"
            contract="ActService.IService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
   
    <!--这里结束添加-->
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"  />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>

  <connectionStrings>
    <add name="ActivitiesEntities" connectionString="metadata=res://*/Activities.csdl|res://*/Activities.ssdl|res://*/Activities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=4CB17D79510E48F;Initial Catalog=Activities;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  
  </connectionStrings>
  <appSettings>
    <!--
            ===================================
            自定义数据库连接信息
    -->
    <add key="ConnectionString" value="Data Source=*.*.*.*;Initial Catalog=A;User ID=ad;Password=*"/>
  </appSettings>
</configuration>
2、silverlight下的配置文件:

<configuration>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="NetTcpBinding_IService">
                    <binaryMessageEncoding />
                    <tcpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://10.2.21.13:4502/ActService/Service.svc"
                binding="customBinding" bindingConfiguration="NetTcpBinding_IService"
                contract="ActService.IService" name="NetTcpBinding_IService" />
        </client>
    </system.serviceModel>
</configuration>

3、web下wcf数据服务的配置文件

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <connectionStrings>
    <add name="ActivitiesEntities" connectionString="metadata=res://*/Activities.csdl|res://*/Activities.ssdl|res://*/Activities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=11.1.21.0;Initial Catalog=A;Persist Security Info=True;User ID=Ad;Password=1;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
 
  </connectionStrings>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  </system.serviceModel>

</configuration>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值