Solved

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

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

751 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