8

I currently have a WCF service with webHttp bindings, im attempting to increase the max size that can be inputted to the service by overriding the default settings in config, i have tried doing something like

  <system.serviceModel>
<bindings>
<webHttpBinding>
  <binding name="webHttp" >
  <security mode="Transport">
      <transport clientCredentialType = 
             "None"
            proxyCredentialType="None"
            realm="string" />
  </security>
  </binding>

</webHttpBinding>
</bindings>
<services>

  <service name="PrimeStreamInfoServices.Service1" behaviorConfiguration="PrimeStreamInfoServices.Service1Behavior">
    <!-- Service Endpoints -->
    <endpoint address="" binding="webHttpBinding"  contract="PrimeStreamInfoServices.IService1">
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="PrimeStreamInfoServices.Service1Behavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<diagnostics>

and setting various other properties pertaining to message size but none seems to be working, can one even change the m essage size of a webHttp binding? Any suggestions? Thanks!

Daniel
  • 22,363
  • 9
  • 64
  • 71

3 Answers3

13

There's a multitude of settings that might have an influence depending on your settings - try this:

<bindings>
  <webHttpBinding>
    <binding name="LargeWeb"
             maxBufferPoolSize="1500000"
             maxReceivedMessageSize="1500000"
             maxBufferSize="1500000">
      <readerQuotas 
            maxArrayLength="656000"
            maxBytesPerRead="656000"
            maxDepth="32"
            maxNameTableCharCount="656000"
            maxStringContentLength="656000"
            />
    </binding>
  </webHttpBinding>
</bindings>

By defining your "version" of the webHttpBinding and setting all those parameters to higher values, you should be able to get through any message size (almost).

Mind you: this does open up your system to the potential of being flooded with huge messages and thus be brought down to its knees (classic denial-of-service attacks) - that's the reason these limits are set fairly low - by design and on purpose.

You can change them to higher values - just be aware what you're doing and what the security risks are, if you do!

Marc

PS: In order to make use of these settings, you of course have to reference that binding configuration in your server and client side configs:

<client>
  <endpoint address="http://localhost"
            binding="webHttpBinding" bindingConfiguration="LargeWeb"
            contract="IMyService" />
</client>
<services>
  <service>
    <endpoint address="http://localhost"
              binding="webHttpBinding" bindingConfiguration="LargeWeb"
              contract="IMyService" />
  </service>
</services>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • This does not work, it wont let me send anything larger than 64k still – Daniel Jul 27 '09 at 16:46
  • Can you show your config? Have you referenced this binding configuration? – marc_s Jul 27 '09 at 16:59
  • Yes i realized this was my problem, i just added the whole config up to, though when i put the bindingCOnfiguration attribute i get an exception, for some reason – Daniel Jul 27 '09 at 17:12
  • I just figured out its because of my security tags there...Would you happen to know why it doesnt like the security settings there by looking at that snippet of config? Thanks! – Daniel Jul 27 '09 at 17:17
  • You specified transport security, e.g. you want to use Https - this requires some setup (SSL certificates etc.) on the client. I assume that might be the problem. – marc_s Jul 27 '09 at 17:19
  • Right, do you have any site with reference of how to do all that that i could look at by any chance? Thanks – Daniel Jul 27 '09 at 18:38
  • "WCF Essentials" is a pretty good intro article - http://www.code-magazine.com/Article.aspx?quickid=0605051 – marc_s Jul 28 '09 at 17:08
  • Or then have a look at Michele Leroux Bustamante's book "Learning WCF" - this is really what got me started into WCF and understanding many of the ins and outs of it all - you'll find it on Amazon or any other good bookstore. – marc_s Jul 28 '09 at 17:09
1

If you are using [DataContract] decorator in your model, you need to add yhe dataContractSerializer into your web.config

Example:

  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpsGetEnabled="false"   httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
MudBit
  • 36
  • 4
0

Setting Max Message and buffer size for WCF Rest services webhttpbinding

<bindings>
  <webHttpBinding>
    <binding maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="200" maxStringContentLength="83886089" maxArrayLength="163841" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
    </binding>
  </webHttpBinding>
</bindings>
Pang
  • 9,564
  • 146
  • 81
  • 122