Ali asjad
Ali asjad

Reputation: 11

WCF Issue: The remote server returned an error: (413) Request Entity Too Large

I know this question has been asked many time before, but unfortunately none of them resolved my issue.

I have a wcf web service in which i can send a file in form of bytes. If the size of the file is large(around 400 KB) this error comes. For small sized files, this issue is not coming. Following is my server endpoint configuration,

<service behaviorConfiguration="CPServicesBehaviour" name="ConsumerPortalAPI.ReceiveNoteService">
  <endpoint address="" binding="customBinding" bindingConfiguration="CustomBinding_IReceiveNoteService" contract="ConsumerPortalAPI.IReceiveNoteService" />
</service>

The binding configuration is,

<binding name="CustomBinding_IReceiveNoteService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
  <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation" requireDerivedKeys="false" includeTimestamp="false" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
  canRenewSecurityContextToken="true">
    <secureConversationBootstrap defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
      <localClientSettings detectReplays="false" />
      <localServiceSettings detectReplays="false" />
    </secureConversationBootstrap>
    <localClientSettings detectReplays="false" />
    <localServiceSettings detectReplays="false" />
  </security>
  <binaryMessageEncoding>
    <readerQuotas maxDepth="32767" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="32767" maxNameTableCharCount="2147483647" />
  </binaryMessageEncoding>
  <httpsTransport />
</binding>

The default binding is,

<binding maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
  <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation" requireDerivedKeys="false" includeTimestamp="false" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
  canRenewSecurityContextToken="true">
    <secureConversationBootstrap defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
      <localClientSettings detectReplays="false" />
      <localServiceSettings detectReplays="false" />
    </secureConversationBootstrap>
    <localClientSettings detectReplays="false" />
    <localServiceSettings detectReplays="false" />
  </security>
  <binaryMessageEncoding>
    <readerQuotas maxDepth="32767" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="32767" maxNameTableCharCount="2147483647" />
  </binaryMessageEncoding>
  <httpsTransport />
</binding>

On my test client side the configuration is,

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="CustomBinding_IReceiveNoteService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
          <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation" requireDerivedKeys="false" includeTimestamp="false" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
          canRenewSecurityContextToken="true">
            <secureConversationBootstrap defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
              <localClientSettings detectReplays="false" />
              <localServiceSettings detectReplays="false" />
            </secureConversationBootstrap>
            <localClientSettings detectReplays="false" />
            <localServiceSettings detectReplays="false" />
          </security>
          <binaryMessageEncoding />
          <httpsTransport />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://cnsportal3.lineartitle.com/cnsAPI/v4/ReceiveNoteService.svc" binding="customBinding" bindingConfiguration="CustomBinding_IReceiveNoteService" contract="CPAction.IReceiveNoteService" name="CustomBinding_IReceiveNoteService" />
    </client>
  </system.serviceModel>
</configuration>

I tried increasing uploadReadAheadSize of my website to 10485759. I also tried increasing maxAllowedContentLength of my website to 3000000000.

I checked the web trace on the server through system.diagnostics. Following is the Xml message that is logged in the trace,

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>524326</EventID>
    <Type>3</Type>
    <SubType Name="Information">0</SubType>
    <Level>8</Level>
    <TimeCreated SystemTime="2015-01-21T11:01:33.3751197Z" />
    <Source Name="System.ServiceModel" />
    <Correlation ActivityID="{90d52ffb-d886-4164-9d84-e74c04eb79b4}" />
    <Execution ProcessName="w3wp" ProcessID="5916" ThreadID="16" />
    <Channel />
    <Computer>RES-DEV-WEB</Computer>
  </System>
  <ApplicationData>
    <TraceData>
      <DataItem>
        <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information">
          <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.GetServiceElement.aspx</TraceIdentifier>
          <Description>Get ServiceElement.</Description>
          <AppDomain>/LM/W3SVC/5/ROOT/cnsAPI/v4-2-130663116927511157</AppDomain>
          <ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/ServiceConfigurationTraceRecord">
            <FoundServiceElement>True</FoundServiceElement>
            <ConfigurationFileSource>C:\inetpub\wwwroot\cnsportal3.lineartitle.com\ConsumerPortalAPI\v4\web.config</ConfigurationFileSource>
            <ConfigurationFileLineNumber>133</ConfigurationFileLineNumber>
            <ServiceConfigurationInformation>
              <ServiceName>ConsumerPortalAPI.ReceiveNoteService</ServiceName>
              <BehaviorConfiguration>CPServicesBehaviour</BehaviorConfiguration>
              <Host>
                <Timeouts>
                  <OpenTimeout>00:01:00</OpenTimeout>
                  <CloseTimeout>00:00:10</CloseTimeout>
                </Timeouts>
              </Host>
              <Endpoints>
                <Endpoint>
                  <Binding>customBinding</Binding>
                  <BindingConfiguration>CustomBinding_IReceiveNoteService</BindingConfiguration>
                  <Contract>ConsumerPortalAPI.IReceiveNoteService</Contract>
                  <ListenUriMode>Explicit</ListenUriMode>
                </Endpoint>
              </Endpoints>
            </ServiceConfigurationInformation>
          </ExtendedData>
        </TraceRecord>
      </DataItem>
    </TraceData>
  </ApplicationData>
</E2ETraceEvent>

This seems that it is able to get the correct Binding Configuration but don't know why it is not using it.

P.S. All bindings are defined under customBinding tag.

Any help in this regard will be highly appreciated. Maybe there is something very small that i am missing here and any one of you can point me to the right direction.

Thanks in advance.

Upvotes: 0

Views: 347

Answers (1)

Ali asjad
Ali asjad

Reputation: 11

I was able to fix the issue by adding following line in my binding configurations.

<httpsTransport maxReceivedMessageSize="2147483647"/>

The whole binding configuration now looks as,

<binding name="CustomBinding_IReceiveNoteService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
		   <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation" requireDerivedKeys="false" includeTimestamp="false" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" canRenewSecurityContextToken="true">
            <secureConversationBootstrap defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
              <localClientSettings detectReplays="false" />
              <localServiceSettings detectReplays="false" />
            </secureConversationBootstrap>
            <localClientSettings detectReplays="false" />
            <localServiceSettings detectReplays="false" />
          </security>
          <binaryMessageEncoding>
            <readerQuotas maxDepth="32767" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="32767" maxNameTableCharCount="2147483647" />
          </binaryMessageEncoding>
          <httpsTransport maxReceivedMessageSize="2147483647"/>
	    </binding>

Upvotes: 1

Related Questions