3

i have created wcf Service in which i am receiving Base64 string and converting base64 string to image to store in my project.

but when i am calling my wcf service method from rest client like this i am getting error like this:

413 Request Entity Too Large

and sometimes nothing happens when i am calling my wcf method from rest client.

enter image description here

above is how i am calling my wcf service method.

above base 64 string is an image of size 177Kb.

but when i am passing small base64 string of image with size 2 kb or 3 kb then my wcf service method is calling.

this is my web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

i have search alot on internet and added this:

<bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>

but error is still not resloved.

can anybody please help me???

1 Answers1

3

While you have defined a basicHttpBinding with larger than default values, you have not told the WCF service to actually use that binding. When no service endpoints are defined, the default out of the box binding is basicHttpBinding with the default values.

You can either set your defined binding as the default binding configuration for any services using basicHttpBinding that use that config file by omitting the name attribute in the binding definition, like this:

<bindings>
  <basicHttpBinding>
    <binding maxBufferPoolSize="2147483647" 
             maxReceivedMessageSize="2147483647" 
             maxBufferSize="2147483647">
      <readerQuotas maxDepth="200" 
                    maxStringContentLength="8388608" 
                    maxArrayLength="16384" 
                    maxBytesPerRead="2147483647" 
                    maxNameTableCharCount="16384" />
    </binding>
  </basicHttpBinding>
</bindings>

OR you can assign the defined binding to an explicit endpoint, which would look something like this:

<services>
  <service name="MyService">
    <endpoint address="" binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IService"
              contract="MyNamespace.IServiceContract" />
    </endpoint>
  </service>

A third place to check is the IIS maximum request length:

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>
</configuration>

If you're uploading very large files you may also want to look at chunking or streaming.

Whole <system.serviceModel>

Option 1: With default binding defined (omitting name attribute from binding configuration)

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding maxBufferPoolSize="2147483647" 
               maxReceivedMessageSize="2147483647" 
               maxBufferSize="2147483647">
        <readerQuotas maxDepth="200" 
                      maxStringContentLength="8388608" 
                      maxArrayLength="16384" 
                      maxBytesPerRead="2147483647" 
                      maxNameTableCharCount="16384" />
      </binding>
    </basicHttpBinding>
  </bindings>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
  <protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
  </protocolMapping>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
                             multipleSiteBindingsEnabled="true" />
</system.serviceModel>

Option 2: With explicit endpoint using specified binding configuration via endpoint's bindingConfiguration attribute:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IService"
               maxBufferPoolSize="2147483647" 
               maxReceivedMessageSize="2147483647" 
               maxBufferSize="2147483647">
        <readerQuotas maxDepth="200" 
                      maxStringContentLength="8388608" 
                      maxArrayLength="16384" 
                      maxBytesPerRead="2147483647" 
                      maxNameTableCharCount="16384" />
      </binding>
    </basicHttpBinding>
  </bindings>
  <services>
    <service name="MyService">
      <endpoint address="" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService"
                contract="MyNamespace.IServiceContract" />
      </endpoint>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
  <protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
  </protocolMapping>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
                             multipleSiteBindingsEnabled="true" />
</system.serviceModel>

Either one of these options should resolve the issue. If they don't, try the third option I gave in my original answer.

Tim
  • 28,212
  • 8
  • 63
  • 76