gpt4 book ai didi

c# - 以编程方式修改端点 ReaderQuotas

转载 作者:IT王子 更新时间:2023-10-29 04:46:32 26 4
gpt4 key购买 nike

我有一个服务的动态客户端。我如何更改其端点绑定(bind)的 ReaderQuotas 属性?

我这样试过,但没用...

 DynamicProxyFactory factory = new DynamicProxyFactory(m_serviceWsdlUri);

foreach (ServiceEndpoint endpoint in factory.Endpoints)
{
Binding binding = endpoint.Binding;

binding.GetProperty<XmlDictionaryReaderQuotas>(new BindingParameterCollection()).MaxArrayLength = 2147483647
binding.GetProperty<XmlDictionaryReaderQuotas>(new BindingParameterCollection()).MaxBytesPerRead =2147483647;
binding.GetProperty<XmlDictionaryReaderQuotas>(new BindingParameterCollection()).MaxDepth = 2147483647;
binding.GetProperty<XmlDictionaryReaderQuotas>(new BindingParameterCollection()).MaxNameTableCharCount = 2147483647;
binding.GetProperty<XmlDictionaryReaderQuotas>(new BindingParameterCollection()).MaxStringContentLength = 2147483647;
}

即使在执行此操作后,ReaderQuotas 值仍保持默认值。

我也这样试过,还是不行:

     DynamicProxyFactory factory = new DynamicProxyFactory(m_serviceWsdlUri);

foreach (ServiceEndpoint endpoint in factory.Endpoints)
{
System.ServiceModel.Channels.BindingElementCollection bec = endpoint.Binding.CreateBindingElements();

System.ServiceModel.Channels.TransportBindingElement tbe = bec.Find<System.ServiceModel.Channels.TransportBindingElement>();

tbe.MaxReceivedMessageSize = 2147483647;
tbe.MaxBufferPoolSize = 2147483647;
TextMessageEncodingBindingElement textBE = bec.Find<TextMessageEncodingBindingElement>();

if (textBE != null)
{

textBE.ReaderQuotas.MaxStringContentLength = 2147483647;
textBE.ReaderQuotas.MaxArrayLength = 2147483647;
textBE.ReaderQuotas.MaxBytesPerRead = 2147483647;
textBE.ReaderQuotas.MaxDepth = 2147483647;
textBE.ReaderQuotas.MaxNameTableCharCount = 2147483647;

}
}

我需要这个,这样我就可以向服务发送超过 8kb 的数据。

最佳答案

在创建绑定(bind)后在 BindingElement 上设置配额对该绑定(bind)没有影响。

编辑(因为您不知道使用什么绑定(bind)):

您可以使用反射来设置属性。请注意,您应该确保 Binding 在设置之前确实具有该属性。并非所有绑定(bind)都具有此属性。如果您尝试在不支持它的绑定(bind)上设置它,该示例将抛出异常。

Binding binding = endpoint.Binding;

XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas();
myReaderQuotas.MaxStringContentLength = _sanebutusablelimit_;
myReaderQuotas.MaxArrayLength = _sanebutusablelimit_;
myReaderQuotas.MaxBytesPerRead = _sanebutusablelimit_;
myReaderQuotas.MaxDepth = _sanebutusablelimit_;
myReaderQuotas.MaxNameTableCharCount = _sanebutusablelimit_;

binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, myReaderQuotas, null);

希望对您有所帮助。

关于c# - 以编程方式修改端点 ReaderQuotas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/969479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com