问题
I am trying to send an array of about 50 elements to a WCF service method, but I'm always receiving a (404) Bad Request
error.
I think that it has to do with the message size or something like that, because if I send an empty array it works.
I did some research and added some stuff in the web.config of the WCF but I still can't manage to get this to work.
Can anyone please provide some additional information as to how I can maybe increase the size of the message I can send?
[UPDATE] Solution:
Solution
回答1:
Stupid, stupid me :(
The thing is that I was creating the binding configuration in the web.config like such:
<bindings>
<wsHttpBinding>
<binding name="netTcpBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="6000000">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="6000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</wsHttpBinding>
</bindings>
But then I was not applying the configuration to the endpoint! So, I had to add this to the endpoint tag:
bindingConfiguration="netTcpBindingConfig"
Now it works like a charm.
回答2:
It's an obvious one but have you tried setting MaxReceivedMessageSize to 65536 and seeing if it still fails?
回答3:
Your service host should be configured to recieve large set of data, if not, it is either dropped at service level.
- Add reference to System.Runtime.Serialization.
When creating the binding set the message size:
return new NetTcpBinding(SecurityMode.None, true) { MaxReceivedMessageSize = 99999999, ReaderQuotas = { MaxArrayLength = 99999999 } };
来源:https://stackoverflow.com/questions/740039/c-sharp-wcf-wcf-service-returning-a-404-bad-request-when-sending-an-array-of