0

I googled quite a lot about this issue. Got many a solutions but none worked for me. I trying to upload an image file using WCF service. Small images get uploaded fine but once the size increase it gives out errors. Here is the error i'm getting

the remote server returned an unexpected response: (413) request entity too large

and here is my web.config(i believe its something to do with the web.config)

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
                <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <behaviors>
        <endpointBehaviors>
            <behavior name="web">
                <webHttp automaticFormatSelectionEnabled="true" />
            </behavior>
        </endpointBehaviors>
        <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">
        <serviceActivations>
            <add factory="System.ServiceModel.Activation.WebServiceHostFactory" relativeAddress="WebService.svc" service="ChargeMe.Service.WebService"></add>
        </serviceActivations>

    </serviceHostingEnvironment>
</system.serviceModel>

Service contract :

[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
ResponseBase SaveAlertSettings(AlertSettingInfo alertSettingInfo);

AlertSettingInfo.fileToUpload has base64string which is first converted to stream and then written to server as an image file. It works fine for small size image file. Throws error for larger file like 4 mb images files.

iJade
  • 23,144
  • 56
  • 154
  • 243
  • Can you show us your service contract? –  Oct 07 '14 at 09:27
  • Thanks. So, **SaveAlertSettings()** uploads images? Maybe show us **AlertSettingInfo** too please if so –  Oct 07 '14 at 09:34

1 Answers1

0

Binding must be added for webHttpBinding

  <webHttpBinding>
    <binding name="webHttpBindingConfig" sendTimeout="05:00:00" hostNameComparisonMode="Exact" maxReceivedMessageSize="2147483647"></binding>
    <binding name="webHttpsBindingConfig" sendTimeout="05:00:00" hostNameComparisonMode="Exact" maxReceivedMessageSize="2147483647">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>
  • Limits must be added to both service and client configurations. If your service isn't configured to handle large size or if you don't have control over it then you can't do anything about it. http://stackoverflow.com/questions/16265725/wcf-error-the-maximum-message-size-quota-for-incoming-messages-65536-has-bee?answertab=active#tab-top – Joseph Jeganathan Oct 07 '14 at 10:13