2011-08-26 130 views
2

我创建了一个WCF REST服务,并成功创建了一个将客户端上的文件上传到服务的功能。无法上传超过64kb到客户端的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))); 
    } 
} 

}

+0

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

+0

中,您可以发布此答案,然后在SO延迟(我认为这是一两天)后接受它。 – Tim

回答

0

想通了。不得不添加属性“maxReceivedMessageSize”和“MAXBUFFERSIZE”我使用Google搜索的

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>