WCF:(400) Bad Request 错误解决方案
![](http://www.csframework.com/images/article-type1.gif)
报错信息:远程服务器返回了意外响应: (400) Bad Request。
经过几次调试,发现小数据量不会出现此错误,如何传输大数据量呢,经过网上搜索和几 次测试发现,只要在服务端和客户端同时增大以下几个配置项。
服务器端:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxBufferPoolSize="5242880000" maxBufferSize="655360000" maxReceivedMessageSize="655360000">
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="test">
<endpoint binding="basicHttpBinding" name="test" contract="Test_Service.Test"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -- >
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
同样在客户端也需要增大与服务器端相同的配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITest" closeTimeout="00:01:00"
&nb sp; openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
&nb sp; allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
&nb sp; maxBufferSize="655360000" maxBufferPoolSize="5242880000" maxReceivedMessageSize="655360000"
&nb sp; messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
&nb sp; useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.test.com/Test.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITest"
contract="TestService.ITest" name="BasicHttpBinding_ITest" />
</client>
</system.serviceModel>