3

我有一个简单的 Web 服务,它需要 2 个参数,一个是简单的 xml 安全令牌,另一个通常是一个长 xml 字符串。它适用于短字符串,但较长的字符串会给出 400 错误消息。maxMessageLength 没有做任何事情来允许更长的字符串。

4

2 回答 2

3

在配额回答之后,我只是在 web.config 中完成了所有这些

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IPayroll" maxReceivedMessageSize="6553600">
      <security mode="None"/>
      <readerQuotas maxDepth="32" 
                    maxStringContentLength="6553600" 
                    maxArrayLength="16384"
                    maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
    </binding>
  </wsHttpBinding>
</bindings>
于 2008-09-26T12:05:02.187 回答
2

您还应该删除配额限制。以下是在代码中使用 Tcp 绑定的方法。我添加了一些代码来显示超时问题的消除,因为通常发送非常大的参数会导致超时问题。所以明智地使用代码......当然,您也可以在配置文件中设置这些参数。

        NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true);

        // Allow big arguments on messages. Allow ~500 MB message.
        binding.MaxReceivedMessageSize = 500 * 1024 * 1024;

        // Allow unlimited time to send/receive a message. 
        // It also prevents closing idle sessions. 
        // From MSDN: To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.’
        binding.ReceiveTimeout = TimeSpan.MaxValue;
        binding.SendTimeout = TimeSpan.MaxValue;

        XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();

        // Remove quotas limitations
        quotas.MaxArrayLength = int.MaxValue;
        quotas.MaxBytesPerRead = int.MaxValue;
        quotas.MaxDepth = int.MaxValue;
        quotas.MaxNameTableCharCount = int.MaxValue;
        quotas.MaxStringContentLength = int.MaxValue;
        binding.ReaderQuotas = quotas;
于 2008-09-25T20:25:36.153 回答