【问题标题】:Cannot upload more than 64kb to WCF REST Service from client无法从客户端上传超过 64kb 到 WCF REST 服务
【发布时间】:2011-11-04 20:16:35
【问题描述】:

我创建了 WCF REST 服务,并成功创建了将文件从客户端上传到服务的函数。

问题是,这仅在发送的文件为 64kb 或更少时才有效。我该如何解决这个问题。

web.config 文件:

<configuration>

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647"/>
</system.web>

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="100000000"> </requestLimits>
    </requestFiltering>
  </security>
  <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
        <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
</system.webServer>

<system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
        <webHttpEndpoint>
            <!-- 
        Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
        via the attributes on the <standardEndpoint> element below
    -->
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
        </webHttpEndpoint>
    </standardEndpoints>
</system.serviceModel>

和 global.asax:

namespace WCFRESTService
{
public class Global : System.Web.HttpApplication
{

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes();
    }

    private void RegisterRoutes()
    {
        // Edit the base address of Service1 by replacing the "Service1" string below
        RouteTable.Routes.Add(new ServiceRoute("RO", new WebServiceHostFactory(), typeof(Service1)));
    }
}

}

【问题讨论】:

  • 想通了。必须将属性“maxReceivedMessageSize”和“maxBufferSize”添加到
  • 你可以发布这个答案,然后在 SO 延迟后接受它(我认为是一两天)。

标签: wcf web-services wcf-rest


【解决方案1】:

经过 3 天的谷歌搜索,我终于找到了解决方案

在我的解决方案 web.config 中,我添加了 https 代码等,之后我删除了所有配置并在下面添加了这个代码

<system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehaviour" name="NativeAppServices.Service1">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding"  contract="NativeAppServices.IService1" behaviorConfiguration="webBehavior">
        </endpoint>
      </service>
    </services>

    <bindings>
      <webHttpBinding>
        <binding name="StreamedRequestWebBinding" closeTimeout="00:25:00"
          openTimeout="00:25:00" receiveTimeout="00:25:00" sendTimeout="00:25:00"
          bypassProxyOnLocal="true" hostNameComparisonMode="WeakWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          transferMode="StreamedRequest" useDefaultWebProxy="false">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
        </binding>
      </webHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors >
        <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
  </system.serviceModel>

  <system.webServer>
    <directoryBrowse enabled="true"/>
  </system.webServer>

【讨论】:

    【解决方案2】:

    想通了。必须将属性“maxReceivedMessageSize”和“maxBufferSize”添加到

    【讨论】:

      猜你喜欢
      • 2011-05-31
      • 2011-09-22
      • 2013-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      • 2017-02-19
      • 1970-01-01
      相关资源
      最近更新 更多