【问题标题】:How to upload file (size is more then 1 mb) using wcf service如何使用 wcf 服务上传文件(大小超过 1 mb)
【发布时间】:2015-11-25 10:34:30
【问题描述】:

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

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

请在下面提交网络配置文件:

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

【问题讨论】:

    标签: wcf silverlight-4.0 wcf-data-services wcf-binding


    【解决方案1】:

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

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

    看看https://stackoverflow.com/a/3853785/87956

    【讨论】:

      【解决方案2】:

      您需要在 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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-31
        • 2011-11-01
        • 2019-05-11
        • 2020-01-18
        • 2012-03-26
        • 2013-12-11
        • 2014-05-29
        相关资源
        最近更新 更多