tags:

views:

270

answers:

2

I'm trying to send a long string by WCF, around 64k chars long. When sending a long string, the I get the HTTP error 400. But when I send shorter string, everything works fine. Here is the WCF interface and app.config that I use.

My message contract:

[MessageContract]
public class MessageClass
{
    [MessageHeader(MustUnderstand = true)]
    public string id;

    [MessageBodyMember(Order=1)]
    public string realMessage;   // Long string
}

I have tried to change the app.config settings by rising the values:

<bindings>
  <basicHttpBinding>
    <binding
      name="ws"
      transferMode="Streamed"
      messageEncoding="Mtom"
      maxReceivedMessageSize="10067108864">
      <readerQuotas
        maxDepth="32"
        maxStringContentLength="2147483647"
        maxArrayLength="2147483647"
        maxBytesPerRead="4096"
        maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

Is there any other value that I should change?

+2  A: 

See the maxReceivedMessageSize attribute of the basicHttpBinding @ http://msdn.microsoft.com/en-us/library/ms731361.aspx. Coindicentally, the default is 65,536 KB.

David Andres
I have set the, maxReceivedMessageSize="10067108864" in my config.
Tuoski
According to the link referenced by this post, the maxReceivedMessageSize is an Integer value. 10,067,108,864 may be a wee-bit too large for a 32-bit Integer value.
David Andres
+3  A: 

You also need to set the "maxBufferSize" and "maxBufferPoolSize" on your binding:

<bindings>
  <basicHttpBinding>
    <binding
      name="ws"
      transferMode="Streamed"
      messageEncoding="Mtom"
      maxReceivedMessageSize="10067108864"
      maxBufferSize="500000" maxBufferPoolSize="500000">
      <readerQuotas
        maxDepth="32"
        maxStringContentLength="2147483647"
        maxArrayLength="2147483647"
        maxBytesPerRead="4096"
        maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

Those also default to 64K in WCF's standard bindings. However, since you're using the "transferMode=Streamed", this really shouldn't be an issue - maybe there's something else going on. How about also increasing the sendTimeout setting? Maybe your service is just taking a tad too long to respond.

Marc

marc_s
The maxBufferSize and maxBufferPoolSize fixed my problem, thanks!
Tuoski