问题
I have a WCF service that has been working fine for some time now, and I decided to add something to it. All of the old stuff works just as it should and the new stuff works for smaller transfers from the client to the host. However, it blows up with a "(400) Bad Request" when the client tries to send large strings to the host. Without changing anything, the host can send items that are just as large or larger to the client with no problem.
I've looked around on here and other sites, and while I've found people with the same problem, their solutions (increasing app.config sizes and lengths) have not yielded any successes for my problem.
Web.config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="Throttled">
<serviceThrottling
maxConcurrentCalls="1000"
maxConcurrentSessions="1000"
maxConcurrentInstances="1000" />
<serviceMetadata
httpGetEnabled="true"
httpGetUrl="" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
app.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"
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="---HostingSiteURL---/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="SimSyncServiceReference.IService" name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
回答1:
First, the "maxReceivedMessageSize" on the client is used only when client receives messages (responses), so in your case you don't have to setup MaxReceivedMessageSize on the client at all; it will never be used. You do need to set it up on the service side.
See other stackoverflow topics on this if you have trouble. See this blog post on how to set this up on the service side in general; it is similar to how you have done it on the client end, as you can imagine.
Second, it is a possibility that this is security-related. In case it is, you might be able to solve the problem by looking at these articles:
http://msdn.microsoft.com/en-us/library/bb628618.aspx http://msdn.microsoft.com/en-us/magazine/cc163570.aspx#S6 http://msdn.microsoft.com/en-us/library/ms733130.aspx
Third, simply reporting a "bad request" as an error message is useless. :-) Please see my answer at WCF not deserializing JSON input for detailed steps on how you can improve your tracing, debugging, and details capabilities so that you can have a better handle on what exactly is going wrong on both the service and client end.
Hope this helps!
回答2:
Have you tried an HTTP POST? You can send a lot more data with a POST than a GET.
来源:https://stackoverflow.com/questions/5690776/need-help-with-the-remote-server-returned-an-unexpected-response-400-bad-re