I am having a puzzling issue that I can't find an answer for. I am trying to Upload a large ammount of data to a WCF service and it will return a 413 error on first and subsequent tries until a request under the 64kb limit is sent after that the large data request is accepted. I have already extended the maxReceivedMessageSize and maxStringContentLength elements in my binding and the this fixes the issue when sending a request after an initial small request (if these aren't extended a different error 400 is returned not a 413).
My system is an ASP.NET 3.5 application running on IIS 7 and the WCF service uses custom binding, SOAP messages and client/server certificates.
Basically the order to reproduce is as follows (tested on 2 servers)
If the maxReceivedMessageSize and maxStringContentLength elements aren't increased the following happens:
Debugging suggests that when receiving the 413 error the server hasn't really initialized my service and once a small request comes in it is initialized and pays attention to my binding rules and then allows for large data quantities.
I suspect this is an issue inside the WCF library and may be fixed by upgrading but that isn't really an option and a need a work around. I was thinking along the lines of on application startup initialize the service in question some how or maybe increase the default WCF maximum received bytes somehow
From My web.config:
<system.web>
<httpRuntime maxRequestLength="65536" executionTimeout="1800"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="67108864" />
</requestFiltering>
</security>
</system.webServer>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceTlsBehavior" name="ELSLookupServiceTLS">
<endpoint address="" binding="customBinding" bindingConfiguration="TlsBinding" contract="Lookup" />
</service>
</services>
<bindings>
<customBinding>
<binding name="TlsBinding" closeTimeout="00:04:00" openTimeout="00:12:00" receiveTimeout="00:15:00" sendTimeout="00:05:00">
<textMessageEncoding>
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
</textMessageEncoding>
<httpsTransport requireClientCertificate="true" maxReceivedMessageSize="6553600" maxBufferPoolSize="6553600" maxBufferSize="6553600" />
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceTlsBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
My Service Implementation:
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class ELSLookupService : Lookup
{
//serivce call implemented here
}
Okay found the problem and for reference sake should someone run into this here is what it was: the error is realated to initial SSL traffic and IIS and seems unrelated to WCF (I could be wrong on that).
The uploadReadAheadSize setting in IIS must be increased.
In IIS7 you can extend this in the web.config under the serverRuntime element, see: http://www.iis.net/configreference/system.webserver/serverruntime
In IIS6 it might also popup and it is apparently an IIS per site setting.