2010-06-29 86 views
4

我寫了一個WCF服務來上傳文件。到目前爲止,我可以上傳300MB的文件大小。當我進一步嘗試時,我收到錯誤提及我們可以使用WCF服務上傳500MB的文件大小嗎?

「底層連接已關閉:連接意外關閉。」

我已經在WCF服務以及客戶端DLL [Uisng Channel factory]中增加了2GB的緩衝區大小。另外我還增加了客戶端的sendTimeout和Receive Timeout以及WCF服務1小時。我還增加了httpruntime元素maxRequestLength爲「2097151」。即使在所有這些設置後,我都無法上傳超過300MB的文件大小。

任何人都可以幫我解決這個問題嗎?

這是WCF服務我的Web配置文件:

<?xml version="1.0"?> 
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use 
    the Website->Asp.Net Configuration option in Visual Studio. 
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
--> 
<configuration> 
    <configSections> 
     <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
       <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
       <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
        <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/> 
        <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
        <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
        <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
       </sectionGroup> 
      </sectionGroup> 
     </sectionGroup> 
    </configSections> 
    <appSettings/> 
    <connectionStrings/> 
    <system.web> 
     <!-- 
      Set compilation debug="true" to insert debugging 
      symbols into the compiled page. Because this 
      affects performance, set this value to true only 
      during development. 
     --> 
     <compilation debug="true"> 
      <assemblies> 
       <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
       <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      </assemblies> 
     </compilation> 
     <!-- 
      The <authentication> section enables configuration 
      of the security authentication mode used by 
      ASP.NET to identify an incoming user. 
     --> 
     <authentication mode="Windows"/> 
     <!-- 
      The <customErrors> section enables configuration 
      of what to do if/when an unhandled error occurs 
      during the execution of a request. Specifically, 
      it enables developers to configure html error pages 
      to be displayed in place of a error stack trace. 

     <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> 
      <error statusCode="403" redirect="NoAccess.htm" /> 
      <error statusCode="404" redirect="FileNotFound.htm" /> 
     </customErrors> 
     --> 
     <pages> 
      <controls> 
       <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      </controls> 
     </pages> 
     <httpHandlers> 
      <remove verb="*" path="*.asmx"/> 
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/> 
     </httpHandlers> 
    <!--Buffer Size Upload--> 
    <httpRuntime maxRequestLength="2097151" executionTimeout="3600"/>  
     <httpModules> 
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     </httpModules> 

    </system.web> 
    <system.codedom> 
     <compilers> 
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
       <providerOption name="CompilerVersion" value="v3.5"/> 
       <providerOption name="WarnAsError" value="false"/> 
      </compiler> 
     </compilers> 
    </system.codedom> 
    <!-- 
     The system.webServer section is required for running ASP.NET AJAX under Internet 
     Information Services 7.0. It is not necessary for previous version of IIS. 
    --> 
    <system.webServer> 
     <security> 
      <requestFiltering> 
       <requestLimits maxAllowedContentLength="52428800"/> 
      </requestFiltering> 
     </security> 
     <validation validateIntegratedModeConfiguration="false"/> 
     <modules> 
      <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     </modules> 
     <handlers> 
      <remove name="WebServiceHandlerFactory-Integrated"/> 
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     </handlers> 
    </system.webServer> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="basicHttpBinding_IVideoUpload"     
       transferMode="Streamed"     
       closeTimeout="00:01:00" 
       openTimeout="00:01:00" 
       receiveTimeout="01:30:00" 
       sendTimeout="01:01:00"     
       bypassProxyOnLocal="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferPoolSize="2147483647" 
       maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647"     
       useDefaultWebProxy="true" 
       allowCookies="false"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> 
      <!--<security mode="Transport"> 
      <transport clientCredentialType="Basic"/> 
      </security>--> 
     </binding>   
     </basicHttpBinding> 
     <customBinding> 
      <binding name="Soap12"> 
       <textMessageEncoding messageVersion="Soap12WSAddressing10" /> 
       <httpTransport transferMode="Streamed" maxReceivedMessageSize="67108864"/> 
      </binding> 
     </customBinding> 
    </bindings>  
     <services> 
      <service behaviorConfiguration="UplaodVideoService.VideoUploadBehavior" name="UplaodVideoService.VideoUpload"> 
       <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_IVideoUpload" contract="UploadVideoProtocol.IVideoUpload"> 
        <identity> 
         <dns value="localhost"/> 
        </identity> 
       </endpoint> 
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
      </service>   
     </services> 
     <behaviors> 
      <serviceBehaviors>   
       <behavior name="UplaodVideoService.VideoUploadBehavior"> 
        <serviceMetadata httpGetEnabled="true"/> 
        <serviceDebug includeExceptionDetailInFaults="true"/>          
       </behavior> 
      </serviceBehaviors> 
     </behaviors>  
    </system.serviceModel> 
</configuration> 

回答

1

一覽設置都似乎是正確的,但......你可能會推動框架或過去在這裏它的極限服務器。你可能很容易就會碰到一些內部錯誤的代碼,甚至會造成服務器過載。

這是一篇很好的文章,可以說明您的問題。特別參見分塊模式: http://weblogs.asp.net/cibrax/archive/2007/08/29/sending-attachments-with-wcf.aspx

如果調整設置更不能幫助您可以通過使用什麼工作着手:

分手了你的大文件分成若干塊(300MB或更少),你知道框架可以管理。然後建立一個會話,您將在其中發佈這些塊並在服務器上重新組裝它們。這就是大多數數據傳輸協議所做的事情,這正是OSI堆棧中正在發生的事情。你只需要模仿這些策略來克服這個限制。

1

我知道這是老看看,但我只是想補充一點,我能弄清楚到底是什麼原因導致我的問題通過使用拋出異常的InnerException。

最外面的異常過於籠統,導致消息「底層連接已關閉:連接意外關閉。」

內部的一個更具描述性,導致消息「無法分配1073741824字節的管理內存緩衝區,可用內存量可能很低。

相關問題