2011-09-28 38 views
0

所以我回顾了大量相同的报告问题,出于某种原因,我无法在我的最终获得工作版本,即使使用现有解决方案来解决这些问题。有人能够阐明我所忽略的一些东西吗?它几乎必须与64k以上的文件上传大小问题相关,因为只要我尝试传递超过该大小的文件,就会立即看到错误。WCF文件流式传输400错误请求

这里是我的WCF服务

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.web> 
    <customErrors mode="Off" /> 
    <compilation debug="true" targetFramework="4.0"> 
     <assemblies> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    <webServices> 
     <protocols> 
     <add name="HttpGet" /> 
     <add name="HttpPost" /> 
     </protocols> 
    </webServices> 
    <sessionState timeout="60" /> 
    <httpRuntime maxRequestLength="2097151" useFullyQualifiedRedirectUrl="true" executionTimeout="14400"/> 
    </system.web> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    </system.webServer> 
    <system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="FileManager" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> 
      <security mode="None"/> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="FileManagerBehavior" name="PrimeWebServices.FileManager"> 
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="FileManager" contract="PrimeWebServices.IFileManager"/> 
     <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="FileManagerBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
      <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

的web.config中,这里是背后

namespace PrimeWebServices 
{ 
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "FileManager" in code, svc and config file together. 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    public class FileManager : IFileManager 
    { 
     public FileManager() 
     { 
      HttpContext httpContext = HttpContext.Current; 

      if (httpContext != null) 
      { 
       httpContext.Response.BufferOutput = false; 
      } 
     } 

     public string UploadStream(Stream stream) 
     { 
      ... 
     } 
    } 
} 

最后我在这里的WCF服务代码是客户端的配置设置(它的一个WinForms客户端,使用一个服务参考)

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IFileManager" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
        messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" 
        useDefaultWebProxy="true"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <security mode="None"> 
         <transport clientCredentialType="None" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="UserName" algorithmSuite="Default" /> 
        </security> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:1116/FileManager.svc" binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IFileManager" contract="PrimeWebServices.IFileManager" 
       name="BasicHttpBinding_IFileManager" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

只要文件下面的应用程序功能正常我看到其他人报告的64kB限制,这让我相信我只是没有正确接线,并且回到默认配置设置。

回答

0

在客户端设置中,确保BasicHttpBinding_IFileManager匹配服务中的FileManager绑定。

1

如果您正在使用IIS,如果你已经安装了请求筛选模块,有一个maxAllowedContentLength限制的请求,默认为28.6MB。这也是你需要调整的。

样本配置(该限制设置为150MB):

<configuration> 
    <system.webServer> 
     <security> 
     <requestFiltering> 
      <requestLimits maxAllowedContentLength="157286400" /> 
     </requestFiltering> 
     </security> 
    </system.webServer> 
</configuration> 

在这里看到更多的信息:http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/requestLimits

1

如果使用ASP.NET开发服务器,那么不支持流模式。您需要将服务部署到IIS或WCF服务应用程序以使用流式传输模式。

+0

这应该是大胆的重要信息。 – 010110110101