Solved

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

Posted on 2008-06-24
4
18,108 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

821 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