3

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

Community
  • 1
  • 1
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360

3 Answers3

2

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.

Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
0

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

sipsorcery
  • 30,273
  • 24
  • 104
  • 155
0

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 }  
    };
    
    
Hadi Eskandari
  • 25,575
  • 8
  • 51
  • 65