如何使用 wcf 服务上传文件(大小超过 1 mb)

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

当我上传小于 64 kb 的文件时可以正常工作,但是当我尝试上传大于 100 kb 的文件时它不起作用。我不知道如何设置 wcf web 配置文件。我花了更多时间来解决这个问题,但我没有找到任何合适的解决方案。我的网络配置中有什么遗漏吗?

我的 wcf 服务名称是:TestServices。Service1.svc

请在下方文件 web 配置文件:

   <?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>

您的应用程序正在选择默认配置。

需要修改httpruntime或在web.config中添加requestlimit标签。

看看。

您需要在web.config中添加requestlimit标签。因此,举个例子:

<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>