3
votes

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

3
if i send 5 elements of the array, I still get the bad request errorAndreas Grech
then its not the size, try focusing on the contents of your array.Konstantinos
but, if i send 3, it works; that's why I'm conferenced about the sizeAndreas Grech
oh hmm then maybe its size related indeedKonstantinos

3 Answers

2
votes

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.

0
votes

It's an obvious one but have you tried setting MaxReceivedMessageSize to 65536 and seeing if it still fails?

0
votes

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 }  
    };