繁体   English   中英

WCF的字符串太长

[英]Too long string for 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
}

我试图通过上升值来更改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>

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

您还需要在绑定上设置“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>

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

请参阅basicHttpBinding @http: //msdn.microsoft.com/en-us/library/ms731361.aspx的maxReceivedMessageSize属性。 Coindicentally,默认值为65,536 KB。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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