[英]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. BasicHttpBinding
类有一个ReaderQuotas
属性,您可以访问该属性来覆盖MaxArrayLength
, MaxBytesPerRead
等属性。
How can I access ReaderQuotas
to achieve the same thing when using an HttpTransportBindingElement
within a CustomBinding
instead of BasicHttpBinding
? 在
CustomBinding
使用HttpTransportBindingElement
而不是BasicHttpBinding
时,如何访问ReaderQuotas
以实现相同的功能?
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
: 您需要使用消息编码绑定元素
TextMessageEncodingBindingElement
而不是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 : 可以使用其他消息编码器类型 (即二进制或MTOM),但如果您进行直接转换,则basicHttpBinding的默认值为text :
The value of WSMessageEncoding that indicates whether MTOM or Text/XML is used to encode SOAP messages.
WSMessageEncoding的值,指示是使用MTOM还是Text / XML来编码SOAP消息。 The default value is Text.
默认值为Text。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.