6

The BasicHttpBinding class has a ReaderQuotas property that you can access to override attributes such as MaxArrayLength, MaxBytesPerRead, etc.

How can I access ReaderQuotas to achieve the same thing when using an HttpTransportBindingElement within a CustomBinding instead of BasicHttpBinding?

i.e.:

var bindingElement = new HttpTransportBindingElement();
bindingElement.MaxBufferSize = 65536; // works
bindingElement.ReaderQuotas.MaxArrayLength = 65536; // error no ReaderQuotas member

var binding = new CustomBinding(bindingElements);
binding .ReaderQuotas.MaxArrayLength = 65536; // also no ReaderQuotas member

Thanks in advance for your help.

Ray
  • 187,153
  • 97
  • 222
  • 204
yogibear
  • 14,487
  • 9
  • 32
  • 31

2 Answers2

4

You need to use the message encoding binding element TextMessageEncodingBindingElement not HttpTransportBindingElement:

        var bindingElement = new TextMessageEncodingBindingElement();
        bindingElement.ReaderQuotas.MaxArrayLength = 65536;

        var binding = new CustomBinding();
        binding.Elements.Add(bindingElement);

The other message encoder types (i.e. binary or MTOM) could be used but if you are doing straight conversion the default for basicHttpBinding is text:

The value of WSMessageEncoding that indicates whether MTOM or Text/XML is used to encode SOAP messages. The default value is Text.

Ray
  • 187,153
  • 97
  • 222
  • 204
2

Can you try the below:

var binding = new CustomBinding();
var myReaderQuotas = new XmlDictionaryReaderQuotas();
myReaderQuotas.MaxStringContentLength = 5242880;
binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, myReaderQuotas, null); 

Hope that helps.

Rajesh
  • 7,766
  • 5
  • 22
  • 35