Solved

Setting WCF binding ReaderQuotas maxStringContentLength with a client generated by code.

Posted on 2008-06-24
4
18,077 Views
Last Modified: 2013-11-06
I do not know how to create a WCF client in code with CustomBinding that has readerQuotas changed to larger value... I have attached a code snippet to show what I am trying to do. When I try to build the project, it says that the readerQuotas property is read-only. I have to create the client with code, I have to provide an assembly that does not need any .config files and has everything included in the assembly.

Can anyone help and give a working code sample ???
CustomBinding custBind = new CustomBinding();
BindingElementCollection bindElemColl = newBindingElementCollection();                
BinaryMessageEncodingBindingElement bindElem = new BinaryMessageEncodingBindingElement();
bindElem.MaxReadPoolSize = 64;
bindElem.MaxWritePoolSize = 16;
bindElem.MaxSessionSize = 2048;
XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
readerQuotas.MaxDepth = 32;
readerQuotas.MaxStringContentLength = largeValue;
readerQuotas.MaxArrayLength = 16384;
readerQuotas.MaxBytesPerRead = 4096;
readerQuotas.MaxNameTableCharCount = 16384;
bindElemColl.ReaderQuotas = readerQuotas;
LAST LINE GIVES ERROR: Error	5	Property or indexer 'System.ServiceModel.Channels.BinaryMessageEncodingBindingElement.ReaderQuotas' cannot be assigned to -- it is read only

Open in new window

0
Comment
Question by:IlpoHokkanen
  • 2
4 Comments
 
LVL 25

Expert Comment

by:apeter
ID: 21858146
ReaderQuotas for BinaryMessageEncodingBindingElement object is Read only thats why you are getting this error.

What ever you are assigning for ReaderQuotas are the default values of BinaryMessageEncodingBindingElement object. So no need to set them once again explicitly.
0
 

Author Comment

by:IlpoHokkanen
ID: 21863237
To Apeter: I do need to set them explicitly, that was just a sample code, and it also had variable largeValue for maxStringlength property that I really do need to set manually. I know that the property is read-only, thats what it says in the error message ! Is there any other way of accomplishing to set the maxStringLength for readerQuotas manually ?
0
 
LVL 25

Accepted Solution

by:
apeter earned 500 total points
ID: 21864987
Create any Binding Derivatives and pass that when creating CustomBinding instance.

XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
readerQuotas.MaxDepth = 32;
readerQuotas.MaxStringContentLength = largeValue;
readerQuotas.MaxArrayLength = 16384;
readerQuotas.MaxBytesPerRead = 4096;
readerQuotas.MaxNameTableCharCount = 16384;

BasicHttpBinding httpBind = new BasicHttpBinding();
httpBind.ReaderQuotas = readerQuotas ;

CustomBinding newCB = new CustomBinding(httpBind);
0
 

Expert Comment

by:mnaumank
ID: 26084150
Using a .config file, you can use the following:
      <customBinding>
        <binding name="soap11BasicHttpBinding" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00">
          <textMessageEncoding messageVersion="Soap11">
            <readerQuotas maxDepth="32" maxStringContentLength="5242880"
                maxArrayLength="5242880" maxBytesPerRead="4096" maxNameTableCharCount="5242880" />
          </textMessageEncoding>
          <httpTransport maxBufferPoolSize="5242880" maxReceivedMessageSize="5242880" maxBufferSize="5242880" />
        </binding>
      </customBinding>
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now