2

Before marking as duplicate or down voting please first go through my scenario. I saw other developers running into the similar problem and tried to apply the solution.

Scenario: The problem is my code is running fine in the development environment, passes staging but fails in the production. Out of the three different upload requests made to the three user machine of the same company 2/3 failed and one uploaded successfully.

error printed in log file for the failing user: "OnUploadFileCompleted: UploadFileCompletedEventArgs has error: Message: The remote server returned an error: (413) Request Entity Too Large."

But the upload file was just 1471834 bytes (1.4 MB approx).

Server Config: I could see that people have been suggesting to set the maxReceivedMessageSize to maximum value which had been already set to 2GB. I tried to replicate the scenario by setting the maxReceivedMessageSize to 300KB than the upload folder size which was around 3MB, but didn't replicate the issue.

Could it be due to some difference in development and production environment that is triggering the issue?

<system.serviceModel>
    <diagnostics performanceCounters="All" />
    <services>
      <service behaviorConfiguration="Psoft.Platform.PSPlatformServiceImplBehavior" name="PenSft.Platform.PSPlatformServiceImpl">
        <endpoint address="net.tcp://localhost:8000/PSPlatform/service" binding="customBinding" bindingConfiguration="Custom_NetTcpBinding" name="clientService" contract="PenSft.Platform.IPSPlatformService" />
        <endpoint address="net.tcp://localhost:8000/PSPlatform/register" binding="customBinding" bindingConfiguration="Custom_NetTcpBinding" name="clientRegister" contract="PenSft.Platform.IClientRegistrationService" />
        <endpoint address="net.tcp://localhost:8001/PSPlatform/service" binding="customBinding" bindingConfiguration="Custom_NetTcpBinding" name="consoleService" contract="PenSft.Platform.IPSPlatformService" />
        <endpoint address="http://localhost:8118/PSPlatform/service" binding="wsHttpBinding" bindingConfiguration="HttpBinding" name="httpClientService" contract="PenSft.Platform.IPSPlatformService" />
        <host>
          <timeouts openTimeout="00:02:00" />
        </host>
      </service>
    </services>
    <bindings>
      <customBinding>
        <binding name="Custom_NetTcpBinding" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:05:00">
          <transactionFlow transactionProtocol="OleTransactions" />
          <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation" requireDerivedKeys="true" securityHeaderLayout="Strict" includeTimestamp="true" keyEntropyMode="CombinedEntropy" messageProtectionOrder="SignBeforeEncryptAndEncryptSignature" messageSecurityVersion="Default" requireSecurityContextCancellation="true" requireSignatureConfirmation="false">
            <secureConversationBootstrap defaultAlgorithmSuite="Default" authenticationMode="MutualSslNegotiated" requireDerivedKeys="true" securityHeaderLayout="Strict" includeTimestamp="true" keyEntropyMode="CombinedEntropy" messageProtectionOrder="SignBeforeEncryptAndEncryptSignature" messageSecurityVersion="Default" requireSecurityContextCancellation="true" requireSignatureConfirmation="false">
              <localClientSettings cacheCookies="true" detectReplays="true" replayCacheSize="900000" maxClockSkew="01:00:00" maxCookieCachingTime="Infinite" replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00" sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true" timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" />
              <localServiceSettings detectReplays="true" issuedCookieLifetime="00:15:00" maxStatefulNegotiations="1000" replayCacheSize="900000" maxClockSkew="01:00:00" negotiationTimeout="00:01:00" replayWindow="00:05:00" inactivityTimeout="00:02:00" sessionKeyRenewalInterval="15:00:00" sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true" maxPendingSessions="1000" maxCachedCookies="1000" timestampValidityDuration="00:05:00" />
            </secureConversationBootstrap>
            <localClientSettings cacheCookies="true" detectReplays="true" replayCacheSize="900000" maxClockSkew="01:00:00" maxCookieCachingTime="Infinite" replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00" sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="false" timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" />
            <localServiceSettings detectReplays="true" issuedCookieLifetime="10:00:00" maxStatefulNegotiations="1000" replayCacheSize="900000" maxClockSkew="01:00:00" negotiationTimeout="00:01:00" replayWindow="00:05:00" inactivityTimeout="00:02:00" sessionKeyRenewalInterval="15:00:00" sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="false" maxPendingSessions="1000" maxCachedCookies="1000" timestampValidityDuration="00:05:00" />
          </security>
          <binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" maxSessionSize="2048">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </binaryMessageEncoding>
          <tcpTransport manualAddressing="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" connectionBufferSize="16384" hostNameComparisonMode="StrongWildcard" channelInitializationTimeout="00:00:30" maxBufferSize="2147483647" maxPendingConnections="2000" maxOutputDelay="00:00:00.5000000" maxPendingAccepts="100" transferMode="Buffered" listenBacklog="300" portSharingEnabled="false" teredoEnabled="false">
            <connectionPoolSettings groupName="default" leaseTimeout="00:05:00" idleTimeout="00:02:00" maxOutboundConnectionsPerEndpoint="2000" />
          </tcpTransport>
        </binding>
      </customBinding>
      <netTcpBinding>
        <binding name="TcpBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Message">
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
      </netTcpBinding>
      <wsHttpBinding>
        <binding name="HttpBinding" closeTimeout="00:05:00"  openTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Message">
            <message clientCredentialType="None" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="PenSft.Platform.PSPlatformServiceImplBehavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceThrottling maxConcurrentCalls="6000" maxConcurrentSessions="6000" maxConcurrentInstances="6000" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="None" />
            </clientCertificate>
            <serviceCertificate findValue="PenSftServiceAuth" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Web.config:

    <system.webServer>
    <!-- security is added to control the allowed upload file size.
    source : http://stackoverflow.com/questions/24930058/file-upload-the-remote-server-returned-an-error-413-request-entity-too-large
    Warning : gives 404 not found error.
    -->
    <!--<security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="30000" /> --><!--in bytes::30 KB --><!--
      </requestFiltering>
    </security>-->
    <modules>
      <add name="PenSftServerHeaderModule" type="PenSftServerHeaderModule"/>
    </modules>
    <handlers>
      <add name="MsiDownloadHandler" verb="*" path="*.msi" type="MsiDownloadHandler, ManagementConsoleV2, Version=1.0.0.0, Culture=neutral" resourceType="Unspecified" />
    </handlers>    
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>

DesktopClient: Few code snippet has been placed. The condition insde event which prints out the particular log has been also placed. If you need more information please let me know.

//inside UploadLogs() funstion.
using (var wc = new WebClient())
{
    wc.UploadFileCompleted += OnUploadFileCompleted;
    wc.UploadFileAsync(address.Uri, null, strLogsFile, strLogsFile);

    ......
    ......
}
//end

private static void OnUploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
{
    .......

    if (e.Cancelled)
    {
        _uploadError = e.Error;
        Log.Trace(string.Format("OnUploadFileCompleted: UploadFileCompletedEventArgs Cancelled has error: Message: {0}", e.Error.Message));
    }

    ....

}
Avishekh Bharati
  • 1,858
  • 4
  • 27
  • 44
  • 1
    Have you tried increasing the uploadReadAheadSize in system.webserver > serverRuntime? I think overrides are defaulted to be denied via the apphost config. Google it some. Your error is typically caused by one of three things, and your binding seems to have all the max limits so its not that, and you have already tried maxAllowContentLength. – Popo May 22 '17 at 17:05
  • Possible duplicate of https://stackoverflow.com/questions/12951763/maximum-request-length-exceeded-in-wcf – arboreal84 May 28 '17 at 11:17

0 Answers0