I'm quite new to WCF services, and I just ran into this known issue, when the uploaded file is too big to upload. My situation is strange because I set both maxAllowedContentLength and maxRequestLength to a high number, so it should have no problems with uploading 300 MB files... With small files it works perfectly, so for me it seems like it just forgets about my settings. I tried so many ideas to solve this problem, so maybe I messed up things in my config file, there may be some unnecessary parts, but still I couldn't find the solution.
I'm working with IIS 10 and .Net 4.5.
My WCF Service configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="4048576" requestLengthDiskThreshold="4048576" executionTimeout="3600" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="TileServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="FileUploadServiceBehavior">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITileService" sendTimeout="01:00:00" maxBufferSize="5000000" />
<binding name="HttpBinding_MTOM"
messageEncoding="Text"
transferMode="Streamed"
maxReceivedMessageSize="4294967294"
maxBufferSize="65536"
maxBufferPoolSize="65536" />
<binding name="BasicHttpBinding_ITileServiceUpload"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536"
maxBufferPoolSize="524288"
maxReceivedMessageSize="4294967294"
messageEncoding="Text"
textEncoding="utf-8"
transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/AEGIS.TileService/TileService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITileServiceUpload" contract="AEGIS.TileService.ITileService" name="BasicHttpBinding_ITileServiceUpload" />
</client>
<services>
<service behaviorConfiguration="FileUploadServiceBehavior" name="AEGIS.TileService.TileService">
<endpoint address="winceStream" binding="basicHttpBinding" bindingConfiguration="HttpBinding_MTOM" contract="AEGIS.TileService.ITileService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295" maxUrl="4294967295" maxQueryString="4294967295" />
</requestFiltering>
</security>
The web.config file from my ASP.NET web app, where the service is referenced.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITileService"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/AEGIS.TileService/TileService.svc/winceStream" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITileService" contract="TileService.ITileService" name="BasicHttpBinding_ITileService"/>
</client>
My upload method is implemented like this:
public void UploadFile(FileUploadMessage request)
{
string basePath = AppDomain.CurrentDomain.BaseDirectory + @"\Images\";
string serverFileName = Path.Combine(basePath, request.Filename);
using (FileStream outfile = new FileStream(serverFileName, FileMode.Create))
{
const int bufferSize = 65536; // 64K
Byte[] buffer = new Byte[bufferSize];
int bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize);
while (bytesRead > 0)
{
outfile.Write(buffer, 0, bytesRead);
bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize);
}
}
}
Where FileUploadMessage is like this:
[MessageContract]
public class FileUploadMessage
{
[MessageHeader(MustUnderstand = true)]
public string Filename;
[MessageBodyMember(Order = 1)]
public Stream FileByteStream;
}
EDIT 1:
I found this article about this issue. Maybe my problem is not with the WCF service or config, but with IIS?
I set the requestLimits of the Default App Pool also to 1000000000. The error still appears.
Also in Option 3 the article writes about changing the ApplicationHost.config. The strange thing is that I don't have anything in that file about requestLimits. Maybe that's the main problem?