2015-11-23 45 views
1

我對WCF服務很陌生,當上傳的文件太大而無法上傳時,我遇到了這個已知問題。我的情況很奇怪,因爲我同時設置了maxAllowedContentLengthmaxRequestLength,因此它應該沒有上傳300 MB文件的問題......對於小文件,它完美地工作,所以對我來說似乎只是忘記了關於我的設置。我嘗試了很多想法來解決這個問題,所以也許我在配置文件中搞砸了一些東西,可能會有一些不必要的部分,但我仍然找不到解決方案。WCF服務 - 404.13錯誤 - 儘管maxAllowedContentLength和maxRequestLength設置爲

我正在使用IIS 10和.Net 4.5。

我的WCF服務配置:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
<system.web> 
<compilation debug="true" targetFramework="4.5" /> 
<httpRuntime targetFramework="4.5" maxRequestLength="4048576" requestLengthDiskThreshold="4048576" executionTimeout="3600" /> 
</system.web> 
<system.serviceModel> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="TileServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    <behavior name="FileUploadServiceBehavior"> 
     <serviceMetadata httpGetEnabled="True" httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<protocolMapping> 
    <add binding="basicHttpsBinding" scheme="https" /> 
</protocolMapping> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_ITileService" sendTimeout="01:00:00" maxBufferSize="5000000" /> 
    <binding name="HttpBinding_MTOM" 
       messageEncoding="Text" 
       transferMode="Streamed" 
       maxReceivedMessageSize="4294967294" 
       maxBufferSize="65536" 
       maxBufferPoolSize="65536" /> 
    <binding name="BasicHttpBinding_ITileServiceUpload" 
       closeTimeout="00:01:00" 
       openTimeout="00:01:00" 
       receiveTimeout="00:10:00" 
       sendTimeout="00:10:00" 
       allowCookies="false" 
       bypassProxyOnLocal="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="65536" 
       maxBufferPoolSize="524288" 
       maxReceivedMessageSize="4294967294" 
       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/AEGIS.TileService/TileService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITileServiceUpload" contract="AEGIS.TileService.ITileService" name="BasicHttpBinding_ITileServiceUpload" /> 
</client> 
<services> 
    <service behaviorConfiguration="FileUploadServiceBehavior" name="AEGIS.TileService.TileService"> 
    <endpoint address="winceStream" binding="basicHttpBinding" bindingConfiguration="HttpBinding_MTOM" contract="AEGIS.TileService.ITileService" /> 
    </service> 
</services> 
</system.serviceModel> 
    <system.webServer> 
<modules runAllManagedModulesForAllRequests="true" /> 
<directoryBrowse enabled="true" /> 
<security> 
    <requestFiltering> 
    <requestLimits maxAllowedContentLength="4294967295" maxUrl="4294967295" maxQueryString="4294967295" /> 
    </requestFiltering> 
</security> 

從我的ASP.NET Web應用程序,如該服務引用的web.config文件。

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_ITileService"/> 
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://localhost/AEGIS.TileService/TileService.svc/winceStream" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITileService" contract="TileService.ITileService" name="BasicHttpBinding_ITileService"/> 
</client> 

我上傳的方法是這樣實現的:

public void UploadFile(FileUploadMessage request) 
    { 
     string basePath = AppDomain.CurrentDomain.BaseDirectory + @"\Images\"; 
     string serverFileName = Path.Combine(basePath, request.Filename); 

     using (FileStream outfile = new FileStream(serverFileName, FileMode.Create)) 
     { 
      const int bufferSize = 65536; // 64K 
      Byte[] buffer = new Byte[bufferSize]; 
      int bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize); 
      while (bytesRead > 0) 
      { 
       outfile.Write(buffer, 0, bytesRead); 
       bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize); 
      } 
     } 
    } 

哪裏FileUploadMessage是這樣的:

[MessageContract] 
public class FileUploadMessage 
{ 
    [MessageHeader(MustUnderstand = true)] 
    public string Filename; 
    [MessageBodyMember(Order = 1)] 
    public Stream FileByteStream; 
} 

編輯1:

http://ipswitchft.force.com/kb/articles/FAQ/Unable-to-transfer-files-over-30MB-with-the-Web-Transfer-Module-or-Ad-Hoc-Transfer-Module-1307565986108

我發現這篇文章是關於這個問題的。也許我的問題不是與WCF服務或配置,但與IIS?

我將默認應用程序池的requestLimits也設置爲1000000000.錯誤仍然出現。

同樣在選項3中,本文將介紹如何更改ApplicationHost.config。奇怪的是我沒有關於requestLimits的文件。也許這是主要問題?

+0

確保您已安裝IIS請求過濾模塊。或者嘗試重新安裝它。 (轉到添加刪除Windows功能 - >萬維網服務 - >安全 - >請求過濾)。這將添加模塊,它應該更新applicationhost文件。 – Dhanuka777

回答

0

您還需要對Web配置進行類似的更改。

您正在使用Web中的「BasicHttpBinding_ITileService」。因此在WCF配置和Web配置文件中需要有類似的配置。

<binding name="BasicHttpBinding_ITileService" 
      maxBufferSize="2147483647" maxBufferPoolSize="2147483647" 
      maxReceivedMessageSize="2147483647"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
       maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
       maxNameTableCharCount="2147483647" /> 
    </binding> 
+0

感謝您的評論,我在我的wcf服務web.config中替換了該綁定,但不幸的是它並未解決我的問題。 :( 我剛剛測試過,目前的限制是30 MB左右 –

+0

您是否具有與web和wcf(客戶端和服務器)綁定的「BasicHttpBinding_ITileService」相同的設置? – Dhanuka777

+0

是的,我將代碼複製粘貼到網頁我的asp.net項目的.config文件和我的wcf服務項目的web.config請檢查編輯我的問題,也許你看到我看不到的東西 –

1

您可能正在處理多個「問題」。

請記得相應地配置您的服務器和客戶端!

首先,我會配置我的。.NET運行庫(WCF)和IIS行爲 https://stackoverflow.com/a/6472631/1498669

注:maxRequestLength的是KILOBYTES而maxAllowedContentLength是BYTES


我想:


  1. 使用的web.config在你的基地webfolder到 '相對' 高價值
<system.webServer> 
<security> 
    <requestFiltering> 

    <!-- maxAllowedContentLength defaults to 30000000 BYTES = 30MB --> 
    <!-- i use 100MB (100 *1024*1024)--> 

    <requestLimits maxAllowedContentLength="104857600" /> 
    </requestFiltering> 
</security> 
</system.webServer> 
設置IIS的默認參數爲特定應用程序(不整臺機器!)
  • 設置在.NET Framework參數到我的預期的「最大」值(至少一個位比IIS值低)的KB,以便能夠捕獲異常之前iis給我一個錯誤的網站(注意:也提高大數據傳輸的超時時間)。
  • <system.web> 
    
    <!-- maxRequestLength defaults to 4096 KILOBYTES = 4MB --> 
    <!-- i use 80MB (80 *1024) --> 
    <!-- please notes that if you use base64 encoded messages --> 
    <!-- you have to calculate the overhead with CEIL(nBytes/3)*4 --> 
    <!-- executionTimeout defaults to 110 SECONDS, is use 5 minutes --> 
    
    <httpRuntime maxRequestLength="81920" executionTimeout="600" /> 
    </system.web> 
    

  • 後,配置我的終端和裹腳布
  • https://msdn.microsoft.com/en-us/library/ms733865.aspx

    也看到https://stackoverflow.com/a/36931852/1498669爲不同屬性和它們的含義。


    作爲參考,該機器web.configs位於(取決於如果使用的是2.0/4.0和32/64位):

    • 32位/ net2.0-3.5
      C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\web.config
    • 32bit/net4.x
      C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config
    • 64bit/net2.0-3。5
      C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Config\web.config
    • 64位/ net4.x - 這主要是獲取Server2008R2使用,並在這些目錄中較高
      C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config

    還有:

    • web.config.default - 您可以複製過web.config重置您的機器配置,如果您無意中更改了機器配置!
    • web.config.comments - 爲ATTRS /元素

    如果你想取得聯繫,所有可用的元素/屬性的具體的解釋 - 請諮詢您的Visual Studio安裝目錄,例如:

    Ç :\ Program Files文件(x86)的\微軟的Visual Studio 14.0 \ XML \架構\ DotNetConfig45.xsd


    OFFT opic:作爲安全設置的附加信息,請參閱https://msdn.microsoft.com/en-us/library/ff648505.aspx

    相關問題