Question

I have a c# winform app.

I am invoking a web service on my server.

In essence I am uploading a byte array.

I know about quotas and I have set them up (I think!) correctly.

I have tried passing zero bytes and the call passes OK.

In my test I am trying to upload 719280 bytes.

I get 400 bad request error.

This is my web.config for the service:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ThrottledBehavior">
          <serviceTimeouts transactionTimeout="0.00:00:30" />
          <serviceThrottling maxConcurrentCalls="64" 
                             maxConcurrentSessions="50" 
                             maxConcurrentInstances="1" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Sync" behaviorConfiguration="ThrottledBehavior">
        <endpoint address="Uploader.svc" 
                  binding="basicHttpBinding"
                  bindingConfiguration="basicHttpBindingEndPoint" 
                  contract="ISync" name="wsUploader"  />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingEndPoint" 
                 maxReceivedMessageSize="2147483647" 
                 messageEncoding="Mtom" 
                 closeTimeout="00:02:00" openTimeout="00:02:00" 
                 maxBufferPoolSize="2147483647" >
          <readerQuotas maxArrayLength="2147483647" 
                        maxBytesPerRead="2147483647" 
                        maxDepth="2147483647" 
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
Was it helpful?

Solution

increase "maxRequestLength" value in

<httpRuntime
      executionTimeout="1200"
      maxRequestLength="1024000"
      appRequestQueueLimit="300" />

Update go to binding configuration and change transfer mode to Streamed

<bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingEndPoint" 
                 maxReceivedMessageSize="2147483647" 
                 transferMode="Streamed"

                 messageEncoding="Mtom" 
                 closeTimeout="00:02:00" openTimeout="00:02:00" 
                 maxBufferPoolSize="2147483647" >
          <readerQuotas maxArrayLength="2147483647" 
                        maxBytesPerRead="2147483647" 
                        maxDepth="2147483647" 
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>

OTHER TIPS

Try turning on tracing (source: MSDN), maybe that'll reveal some details. Add this to your web.config:

<configuration>
   <system.diagnostics>
      <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="traceListener" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "c:\log\Traces.svclog" />
            </listeners>
         </source>
      </sources>
   </system.diagnostics>
</configuration>

my particular issue was that I was using Throttled behaviour. This setting is OK for small data but not large. So changing this binding to normal/standard behaviour like so:

    <behavior name="NormalBehaviour">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>

instead of using this:

    <behavior name="ThrottledBehavior">
      <serviceTimeouts transactionTimeout="0.00:00:30" />
      <serviceThrottling maxConcurrentCalls="64" maxConcurrentSessions="50" maxConcurrentInstances="1" />
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>

worked for me.

The essence here is that the 'serviceThrottling' has been removed. I could have kept this in but then I would have to increase the maxConcurrentCalls, maxConcurrentSessions and maxConcurrentInstances which I did try but was counter productive to throttled behaviour and thus took a lot longer to process.

Thanks to everyone giving their time to this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top