让IIS支持WCF的netTcpBinding

使用WCF的时间不是很长,但是感觉他博大精深,将网络通信的复杂完全隐藏在一个配置文件和接口中。
因为我搞过SOCKET通信模块的编写,对此深有体会!

问题来源,IIS原生支持HTTP协议,不需要做过多的配置就能够让使用这个协议的WCF接口工作,具体协议为basicHttpBinding,wsHttpBinding。但是在测试的过程当中发现netTcpBinding协议的传输速度是basicHttpBinding的三倍以上,所以想使用netTcpBinding协议作为WCF接口的数据传输途径。

但是要让IIS支持WCF的netTcpBinding比较费力,在研究了数天之后总算得到了解决方案。

Web.config具体配置如下:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="TempBehavior">
          <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <!--设置连接数量-->
          <serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647"/>
          <!--安全验证-->
          <!--<serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="None"/>
            </clientCertificate>
          </serviceCredentials>-->
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--接收数据大小,加密设置:transport,默认安全级别为加密和完整性验证-->
    <bindings>
      <netTcpBinding>
        <binding name="TempNetTcpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="None"/>
            <message clientCredentialType="Windows"/>
          </security>
        </binding>
      </netTcpBinding>
      <!--<wsHttpBinding>
        <binding name="TempWsHttpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
          <security mode="None">
            <transport clientCredentialType="Windows"/>
            <message clientCredentialType="Windows"/>
          </security>
        </binding>
      </wsHttpBinding>-->
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <services>
      <service behaviorConfiguration="TempBehavior" name="TempWcf.Server.ServiceTemp">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="TempNetTcpBinding" contract="TempWcf.Server.IServiceTemp"/>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      </service>
      <!--<service behaviorConfiguration="TempBehavior" name="TempWcf.Server.ServiceTemp">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="TempWsHttpBinding"
  contract="TempWcf.Server.IServiceTemp" />
      </service>-->
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

上图就是我的配置文件,关键代码有两处,一处是:

    <services>
      <service behaviorConfiguration="TempBehavior" name="TempWcf.Server.ServiceTemp">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="TempNetTcpBinding" contract="TempWcf.Server.IServiceTemp"/>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      </service>

上面的代码规定了IIS配置使用NET.TCP协议;

另外一处是:

          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="None"/>
            <message clientCredentialType="Windows"/>
          </security>

上面的代码是安全协议;
上面两处中任何一处配置不对都会导致netTcpBinding协议不能正确运行。

其二,需要配置IIS支持net.tcp协议

具体设置如下:

让IIS支持WCF NET.TCP协议的配置

经过以上两步的配置,就可以让IIS支持WCF的netTcpBinding了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值