WCF 修改 CustomBinding 中 HttpTransportBindingElement 的 ReaderQuotas

发布于 2025-01-01 05:23:35 字数 659 浏览 1 评论 0原文

BasicHttpBinding 类具有一个 ReaderQuotas 属性,您可以访问该属性来覆盖 MaxArrayLengthMaxBytesPerRead 等属性。

CustomBinding 中使用 HttpTransportBindingElement 而不是时,如何访问 ReaderQuotas 来实现相同的效果BasicHttpBinding

即:

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

提前感谢您的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咆哮 2025-01-08 05:23:35

您需要使用消息编码绑定元素 TextMessageEncodingBindingElement 而不是 HttpTransportBindingElement

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

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

另一个 消息编码器类型(即二进制或MTOM)可以使用,但如果您正在进行直接转换basicHttpBinding 的默认值为文本

WSMessageEncoding 的值,指示是 MTOM 还是 Text/XML
用于对 SOAP 消息进行编码。默认值为文本。

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.

怕倦 2025-01-08 05:23:35

您可以尝试以下方法吗:

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

希望有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文