远程服务器返回了意外响应 400 Bad Request
远程服务器返回了意外响应 400 Bad Request。原因在于:传输的数据量过大。
解决方案:
首先在客户端(client)的配置文件里:
1.在节点<binding>修改传输数据的最大额度:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_USService1" closeTimeout="00:03:00"
openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8001/usinfoservices" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_USService1" contract="ServiceReference2.USService"
name="BasicHttpBinding_USService1" />
</client>
</system.serviceModel>
然后在修改服务器端<Hosting>的配置文件:
1.在节点<binding>修改传输数据的最大额度:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="newBinding" maxBufferPoolSize="21474835647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="metadataBehavior" name="Genesysinfo.USServices.Services.USInfoServices">
<endpoint address="" bindingConfiguration="newBinding" binding="basicHttpBinding" contract="Genesysinfo.USServices.Contracts.IUSInfoServices" />
<endpoint address="" binding="netTcpBinding" contract="Genesysinfo.USServices.Contracts.IUSInfoServices" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8001/usinfoservices" />
<add baseAddress="net.tcp://localhost:8000/usinfoservices" />
</baseAddresses>
</host>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
就OK了。