简体   繁体   中英

Too long string for WCF

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM