码迷,mamicode.com
首页 > 其他好文 > 详细

WCF LIST 传输大数据,远程服务器返回了意外响应 400

时间:2016-12-02 18:56:54      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:tle   idc   out   app   .config   复杂   data   metadata   svc   

WCF传输LIST 大数据量 出现 远程服务器返回了意外响应 400 错误提示。

出现这个问题,各种搜索,都没有解决问题,而且有些都比较复杂,自己琢磨了一下,其实也不是很难,好了,看下面方案。
解决方案:
在web.config(host)端<system.serviceModel>节中, 增加 services 节 如下:
<services>
      <service behaviorConfiguration="app.dcgkbehavior" name="ErpAssistWCF.DCGKService"  >
        <endpoint  address="" binding="wsHttpBinding" bindingConfiguration="BindConfig"

contract="ErpAssistWCF.IDCGKService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
</services>

service中的name 设置 为 wcf库名+wcf SVC 文件名。
endpoint中contract 设置为 wcf库名+wcf CONTRACT 文件名。

注意这里的几个关键项: behaviorConfiguration,bindingConfiguration,binding

先看第一个关键项,看下面的<behaviors>节的配置:
看到<behaviors>中有两个配置,其中一个name="",这个behavior节是必须有的,不可以删除。
看第二个behavior节,name为app.dcgkbehavior,这个name可以随便取,但是,但是,但是,重要的事

情说三遍,这个name 必须要和上面提到的service 节中  behaviorConfiguration后的名字必须一致。

 
<behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceTimeouts transactionTimeout="00:50:00"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceThrottling maxConcurrentCalls="2147483647"

maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647"/>
        </behavior>
        <behavior name="app.dcgkbehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceTimeouts transactionTimeout="00:50:00"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceThrottling maxConcurrentCalls="2147483647"

maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
下面说第二个关键字 bindingConfiguration ,看下面的<bindings>节:
对了,第二个关键字 bindingConfiguration 后对应的名字就是这个接种 binding节的name,即为:
BindConfig

<bindings>
      <wsHttpBinding>
        <binding name="BindConfig" closeTimeout="00:10:00"
            openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
            bypassProxyOnLocal="false" transactionFlow="false"

hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
            allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647"

maxArrayLength="2147483647"
              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
         
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="None" negotiateServiceCredential="true"
                algorithmSuite="Default" establishSecurityContext="true" />
          </security>
         
        </binding>
      </wsHttpBinding>
     
    </bindings>
下面说第三个关键字 binding ,看上面的 <bindings>节中,我这里使用的是 <wsHttpBinding>,所以

,binding关键字等于 “wsHttpBinding”。

以上就是在 webconfig中的设置。
设置完毕后,重新生成WCF。然后在 客户端,将引用的wcf服务删掉,重新引用。VS会自动更新

app.config。生成 配置后,其中字节的允许大小还是默认的,可以参照服务端配置,将数值改为最大

2147483647 。
下面为 app.config生成的配置:

<wsHttpBinding>
                <binding name="WSHttpBinding_IDCGKService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00"

sendTimeout="00:10:00"
                    bypassProxyOnLocal="false" transactionFlow="false"

hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="2147483647"

maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="Windows"

proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows"

negotiateServiceCredential="true" />
                    </security>
                </binding>
            </wsHttpBinding>

WCF LIST 传输大数据,远程服务器返回了意外响应 400

标签:tle   idc   out   app   .config   复杂   data   metadata   svc   

原文地址:http://www.cnblogs.com/leoyang0123/p/6126454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!