WCF XmlDictionaryReaderQuotas不存在

时间:2012-05-26 13:11:41

标签: c# wcf

我想在basichtttpbiding中设置maxArrayLength。 但是,执行此操作的唯一方法是使用配置文件,创建一个XmlDictionaryReaderQuotas,在System.xml中不存在,并将其放在BasicHttpBinding1.ReaderQuotas中。

如何在不使用配置文件的情况下设置maxArrayLength

编辑:

我不能这样做:basichtttpbiding1.ReaderQuotas.MaxArrayLength = 1000000;因为我之后没有任何选择:basichtttpbiding1.ReaderQuotas。[可供选择的选项]

2 个答案:

答案 0 :(得分:22)

<强>解决。

需要手动添加引用:System.Runtime.Serialization 然后类XmlDictionaryReaderQuotas将显示在System.Xml

答案 1 :(得分:3)

您无需创建XmlDictionaryReaderQuotas的实例。绑定已经有一个这样的实例,所以你可以直接使用它:

BasicHttpBinding bhb = new BasicHttpBinding;
bhb.ReaderQuotas.MaxArrayLength = 1000000;

但是,如果您使用的是Silverlight等平台(如果是这种情况,请在您的问题中添加相应的标签),此属性不会公开。这是因为在该平台中没有强制执行此配额 - 它基本上与配额存在时的行为相同,但它被设置为最大值(int.MaxValue)。所以你不需要增加它(它已经最大化了),你不能减少它。