WCF - How to accept long strings as parameters

I have a simple web service, it takes 2 parameters, one is a simple xml security token, the other is a long xml string. It works with short lines, but longer lines give an error message of 400. maxMessageLength did nothing to allow longer lines.

+3
source share
2 answers

After responding to quotas, I just did all this in the web.config file

<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>
+3
source

. 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 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;
+2

Source: https://habr.com/ru/post/1697537/


All Articles