WCF双工通信外网无法连接

由于项目需要把WCF部署外网,在公司完成程序,测试没有问题,wsDualHttpBinding 双工通信

客户端配置:

<system.serviceModel>

    <bindings>

      <wsDualHttpBinding>

        <binding name="hhh_IBLLServiceContract" closeTimeout="00:01:00"

            openTimeout="00:51:00" receiveTimeout="00:50:00" sendTimeout="00:51:00"

            bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"

            maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"

            messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true">

          <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"

              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

          <reliableSession ordered="true" inactivityTimeout="00:50:00" />

          <security mode="None">

            <message clientCredentialType="Windows" negotiateServiceCredential="true" />

          </security>

        </binding>

      </wsDualHttpBinding>

    </bindings>

    <client>

      <endpoint address="http://192.168.9.29:8081/Service1.svc"

          binding="wsDualHttpBinding" bindingConfiguration="hhh_IBLLServiceContract"

          contract="IBLLServiceContract" name="hhh_IBLLServiceContract">

       

      </endpoint>

    </client>

  </system.serviceModel>

 

服务器端配置:

 

<system.serviceModel>



    <bindings>

      <wsDualHttpBinding>

        <binding name="hhh" messageEncoding="Mtom">

          <security mode="None"/>

        </binding>

      </wsDualHttpBinding>

    </bindings>



    <services>

      <service behaviorConfiguration="serviceBehavior" name="RNOP.WCF.Service.BLLService">

        <endpoint address="Service1.svc"

          binding="wsDualHttpBinding" bindingName="hhh" bindingConfiguration="hhh" contract="RNOP.WCF.ServiceInterface.IBLLServiceInterface" >

        </endpoint>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" >

        </endpoint>

        <host>

          <baseAddresses>

            <add baseAddress="http://192.168.9.180:8081/" />

          </baseAddresses>

        </host>

      </service>

    </services>

    <behaviors>

      <serviceBehaviors  >

        <behavior name="serviceBehavior">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="False" />

          <dataContractSerializer maxItemsInObjectGraph="2147483647" />



        </behavior>



      </serviceBehaviors>



    </behaviors>

  </system.serviceModel>

 

内网测试没有问题,部署到外网,就报超时异常operation may have been a portion of a longer timeout

检查服务器和客户端防火墙是否关闭,防火墙都关闭,依然连接失败;

检查端口是否被占用,更换端口,错误依然;

发现服务的网页上元数据地址使用的是计算机名,而计算机名称在外网是无法访问,于是搜索,在网上发现一篇文章:http://www.cnblogs.com/lensso/archive/2011/08/01/2124095.html

远程客户端由于元数据地址主机名为服务器计算机名而无法解析WCF服务元数据的解决办法

安装文章方法解决的了元数据的地址解析问题。

但是客户端依然无法连接服务端,再次

http://www.cnblogs.com/bryant/archive/2011/09/22/2185621.html

http://social.msdn.microsoft.com/Forums/en-US/wcfzhchs/thread/0d663107-b47e-464b-82dc-6f191c484870

所以在外网的情况下,程序能正常的工作必须确保:1.客户端没安装IIS6以下的版本,即80端口要被空出来;2是在违反1的条件下,80端口被占用,让你的clientBaseAddress能被服务器所识别。

于是设置地址,客户端正常连接上服务端,问题解决。

你可能感兴趣的:(WCF)