WCF的字符串太长

Tuo*_*ski 2 .net c# string wcf

我正在尝试通过WCF发送长字符串,大约64k字符长.当发送一个长字符串时,我得到HTTP错误400.但是当我发送更短的字符串时,一切正常.这是我使用的WCF接口和app.config.

我的留言合同:

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

    [MessageBodyMember(Order=1)]
    public string realMessage;   // Long string
}
Run Code Online (Sandbox Code Playgroud)

我试图通过上升值来更改app.config设置:

<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>
Run Code Online (Sandbox Code Playgroud)

还有其他价值我应该改变吗?

mar*_*c_s 5

您还需要在绑定上设置"maxBufferSize"和"maxBufferPoolSize":

<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>
Run Code Online (Sandbox Code Playgroud)

在WCF的标准绑定中,这些也默认为64K.但是,既然你正在使用"transferMode = Streamed",这真的不应该是一个问题 - 也许还有其他事情发生.如何增加sendTimeout设置?也许你的服务只是花了太长时间来回应.