WCF modification of ReadQuotas for HttpTransportBindingElement in CustomBinding

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

How can I access ReaderQuotas to achieve the same goal when using the HttpTransportBindingElement inside 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.

+4
source share
2 answers

Can you try the following:

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

Hope this helps.

+2
source

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

  var bindingElement = new TextMessageEncodingBindingElement(); bindingElement.ReaderQuotas.MaxArrayLength = 65536; var binding = new CustomBinding(); binding.Elements.Add(bindingElement); 

You can use other types of message encoders (for example, binary or MTOM), but if you are performing a direct conversion , the default value for basicHttpBinding is the text :

A WSMessageEncoding value that indicates whether MTOM or Text / XML will be used to encode SOAP messages. The default value is text.

0
source

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


All Articles