Solved

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

Posted on 2008-06-24
4
18,196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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 column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

632 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