简体   繁体   中英

WCF modifying ReaderQuotas for HttpTransportBindingElement in CustomBinding

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 ?

ie:

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.

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.

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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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