解决wcf数据量过大时出现的错误

2015-6-12 9:36

碰到wcf接口调用出错,错误信息“接收对 http://test0019.httest.loc:2257/MemberService.svc 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。有关详细信息,请参见服务器日志。”

检查发现,查询到的数据量大的时候就出这个错误,数据量小时候正常。按照网上多方查找,最后解决办法如下。

web.config文件binding做如下修改

    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingConfiguration"  maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647" >
          <security mode="None" />
          <readerQuotas maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxDepth="2147483647"
                        maxNameTableCharCount="2147483647"
                        maxStringContentLength="2147483647"/>
        </binding>
      </wsHttpBinding>


    </bindings>

behavior中添加<dataContractSerializer maxItemsInObjectGraph="65536000" />修改后如下

        <behavior name="Htinns.CRM.BIL.WCF.MemberServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceThrottling maxConcurrentCalls="80" maxConcurrentInstances="180" maxConcurrentSessions="100"/>
<dataContractSerializer maxItemsInObjectGraph="65536000" />
        </behavior>

用wcf test client调用后发现仍然报错,错误信息如下:

“已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性。”

按照提示修改客户端的配置,最后得以解决。修改后客户端配置如下:

        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IMemberService" sendTimeout="00:05:00"
                    maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </wsHttpBinding>
        </bindings>

 

点击:loading..
收藏到:中国收客网
评论