Search code examples
wcfsilverlight-4.0wcf-data-serviceswcf-binding

How to upload file (size is more then 1 mb) using wcf service


When I upload file less then 64 kb then is works fine but when I try to upload file more then 100 kb then it does not work. I do not how to set wcf web config file. I have spent more time to solve this issue but I did not find any proper solution. Is there anything miss in my web config?

My wcf service name is :TestServices.Service1.svc

Please below file web config file:

   <?xml version="1.0"?>
<configuration>

  <connectionStrings>
    <add name="TestEntities" connectionString="metadata=res://*/IHSDataModel.csdl|res://*/IHSDataModel.ssdl|res://*/IHSDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=S01;initial catalog=TestDb;persist security info=True;user id=sa;password=sa@123;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>   
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="2147483647"/> 
  </system.web>
  <system.serviceModel>    
    <behaviors>
      <serviceBehaviors>
        <behavior>         
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>   
    <directoryBrowse enabled="true"/>
  </system.webServer>
  <system.serviceModel>
    <diagnostics>
      <messageLogging
           logEntireMessage="true"
           logMalformedMessages="false"
           logMessagesAtServiceLevel="true"
           logMessagesAtTransportLevel="false"/>
    </diagnostics>
  </system.serviceModel>
</configuration>

Solution

  • You need to add requestlimit tag in web.config. So, as an example:

    <location path="Documents/Upload">
      <system.web>
        <!-- 50MB in kilobytes, default is 4096 or 4MB-->
        <httpRuntime maxRequestLength="51200" />
      </system.web>
      <system.webServer>
        <security>
          <requestFiltering>
            <!-- 50MB in bytes, default is 30000000 or approx. 28.6102 Mb-->
            <requestLimits maxAllowedContentLength="52428800" /> 
          </requestFiltering>
        </security>
      </system.webServer>
    </location>