Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
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…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

771 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

11 Experts available now in Live!

Get 1:1 Help Now