sha
sha

Reputation: 17860

Which exactly MaxReceivedMessageSize should be increased

Looks like this question has been asked thousand times already, but each person's configuration problems are different. I have WCF server that serves images and also receives upload image requests. When uploading images I'm getting error 400 when size is more then 65k.

I turned the trace on the WCF and I'm getting exact error

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

I know that I need to increase this parameters but I'm just can find where is it supposed to be in my web.config file. Here is what I have in web.config:

  <system.serviceModel>
    <protocolMapping>
      <add binding="webHttpBinding" scheme="http" />
    </protocolMapping>
    <services>
      <service behaviorConfiguration="ReportTransferServiceBehavior" name="ReportTransferService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ReportTransferService" contract="IReportTransferService"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="ReportTransferServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <domainServices>
      <endpoints>
        <add name="json" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
            maxReceivedMessageSize="2000000" />
      </endpoints>
    </domainServices>
    <bindings>
      <basicHttpBinding>
        <binding name="ReportTransferService" maxReceivedMessageSize="2000000" maxBufferSize="2000000" transferMode="Streamed">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
          <security mode="None"></security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>

The URL I'm sending images (HTTP POST) is hostname/ReportTransferService.svc/UploadImage. Looks like it's using some kind of default binding and not basicHttpBinding configured for bigger size.

Anyone can tell me what's wrong with my web.config?

Update: Resolved

I had to specify fully qualified name for ReportTransferService in service configuration and serviceBehavior configuration and added whole new webHttpBinding section with similiar limits and pointed service to use this binding.

Thanks for your help.

Upvotes: 1

Views: 1232

Answers (1)

Rajesh
Rajesh

Reputation: 7886

Your service section should have fully qualified names as shown below:

     <services>
      <service behaviorConfiguration="ReportTransferServiceBehavior" name="namespace.ReportTransferService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ReportTransferService" contract="namespace.IReportTransferService"></endpoint>
      </service>
    </services>

Upvotes: 1

Related Questions