Compartir a través de


How to change reader quota values programmatically

Example:

XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();

quotas.MaxArrayLength = int.MaxValue;

quotas.MaxBytesPerRead = int.MaxValue;

quotas.MaxDepth = int.MaxValue;

quotas.MaxNameTableCharCount = int.MaxValue;

quotas.MaxStringContentLength = int.MaxValue;

NetTcpBinding tcpBinding = new NetTcpBinding();

tcpBinding.ReaderQuotas = quotas;

Comments

  • Anonymous
    October 09, 2008
    That's it?  You don't have to set this new NetTcpBinding somewhere? It just magically works?

  • Anonymous
    October 16, 2008
    If you have self host app, This is how complete code looks like // Host the service within this EXE console application.        public static void Main()        {            //Define reader quotas                XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();                quotas.MaxArrayLength = int.MaxValue;                quotas.MaxBytesPerRead = int.MaxValue;                quotas.MaxDepth = int.MaxValue;                quotas.MaxNameTableCharCount = int.MaxValue;                quotas.MaxStringContentLength = int.MaxValue;            //Assign reader quotas to binding                NetTcpBinding tcpBinding = new NetTcpBinding();                tcpBinding.ReaderQuotas = quotas;            //use above binding                ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService),new Uri("http://localhost:8081/testsvc"));                serviceHost.AddServiceEndpoint("Microsoft.ServiceModel.Samples.ICalculator", tcpBinding, new Uri("net.tcp://localhost:9000/testsvc1/ep1"));                serviceHost.Open();                Console.WriteLine("service is ready");                Console.ReadKey();        }

  • Anonymous
    March 29, 2009
    Hi, I'm developing WCF application. During  which I'm getting error "The remote server returned an unexpected response: (400) Bad Request." even after  increasing the request quota size in the configuration file at the client side to "2147483647" Can you please help me out to resolve the issue. Regards, Sreejith

  • Anonymous
    July 31, 2009
    We may get 400 Bad request for different reasons, it may or may not be related to reader quotas, Please enable WCF tracing, Tracing will show why server throwing 400 error http://blogs.msdn.com/madhuponduru/archive/2006/05/18/601458.aspx