Efrat T
Efrat T

Reputation: 23

Large images with wcf - ThrowMaxReceivedMessageSizeExceeded()

I've created a WCF Service to upload images. It works fine with vary small images. But when I try it with image like 800KB I get "The remote server returned an error: (400) Bad Request." When I look on the log file I see this exception: ThrowMaxReceivedMessageSizeExceeded() I've been looking for ages and tried lots of different things, including setting the maxRequestLength and several other settings.

I have WCFApp, WebApplocation-for my site, and classLibrary-for the BLClient that has the service referece.

These are my config files:

Web.config of the WCFApplication:

 <?xml version="1.0"?>
     <configuration>
  <connectionStrings>
    <add name="photoShopEntities"
         connectionString="metadata=res://*/photoShop.csdl|
         res://*/photoShop.ssdl|
         res://*/photoShop.msl;
         provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|photoShop.mdf;Integrated Security=True;User Instance=True'"
         providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

Web.config of the WebApplication:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>

    <roleManager enabled="true">
      <providers>
        <clear />
        <add connectionStringName="ApplicationServices" applicationName="/"
          name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider"
          type="System.Web.Security.WindowsTokenRoleProvider" />
      </providers>
    </roleManager>


  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>



  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IBLServer" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:50739/PhotoShopWS.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IBLServer" contract="PhotoShopWS.IBLServer"
          name="BasicHttpBinding_IBLServer" />
    </client>
  </system.serviceModel>
</configuration>

App.config of the classLibrary:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IBLServer" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:50739/PhotoShopWS.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IBLServer" contract="PhotoShopWS.IBLServer"
          name="BasicHttpBinding_IBLServer" />
    </client>
  </system.serviceModel>
</configuration>

I saw a lot of answers about it but my problem stil leave. Any help is greatly appreciated!

Upvotes: 1

Views: 1379

Answers (3)

Efrat T
Efrat T

Reputation: 23

I used mark help, now my site allow to upload large images.

This is the web.config of my WCFApplication after the changes.

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="photoShopEntities"
         connectionString="metadata=res://*/photoShop.csdl|
         res://*/photoShop.ssdl|
         res://*/photoShop.msl;
         provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|photoShop.mdf;Integrated Security=True;User Instance=True'"
         providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding transferMode="Streamed"
                maxReceivedMessageSize="67108864">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <!-- other config here -->
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>

          <!-- 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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

Thanks a lot!!

Upvotes: 1

VJAI
VJAI

Reputation: 32758

It is in the web.config of the WCF application you have to specify the maxReceivedMessageSize to a higher value.

Ex.

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
             <binding transferMode="Streamed"
                     maxReceivedMessageSize="67108864">
               <!-- other config here -->
            </binding>
        </basicHttpBinding>
    </bindings>
</system.serviceModel>

Upvotes: 3

Mazhar Karimi
Mazhar Karimi

Reputation: 157

Check

if it exist in httpTransport element, in App.config of the classLibrary:

maxReceivedMessageSize="104857600"

Upvotes: 0

Related Questions