无法从客户端上传超过64kb的WCF REST服务

时间:2011-08-26 20:54:37

标签: wcf web-services wcf-rest

我创建了一个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)));
    }
}

}

2 个答案:

答案 0 :(得分:1)

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

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

&#13;
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

想出来。不得不将属性“maxReceivedMessageSize”和“maxBufferSize”添加到