2011-09-28 66 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