开发者

Can we upload a file size of 500MB using WCF Service?

开发者 https://www.devze.com 2023-01-04 22:43 出处:网络
I have written a WCF Service to upload a file. So far i am able to upload a file size of 300MB. When i tried further i am receiving an error mentioning

I have written a WCF Service to upload a file. So far i am able to upload a file size of 300MB. When i tried further i am receiving an error mentioning

"The underlying connection was closed: The connection was closed unexpectedly."

I have increased the buffer size to 2GB in WCF service as well the client DLL[Uisng Channel factory] . Also i have increased the sendTimeout and Receive Timeout in Client aswell the WCF service to 1 hour. I have also increased the httpruntime elements maxRequestLength to"2097151". Even after all these settings i couldn't upload file size more than 300MB.

Can anyone pls help me out on this?

This is my Web Config file of WCF Service:

<?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="Scri开发者_运维技巧ptResource" 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>


At a glance your settings all seems to be right but... You're probably pushing the framework or the server past its limits here. You could easily be hitting some deep, internal piece of code that has an errant upper bound or even overloading the server.

Here's a great article that speaks to your issues. See the chunking mode especially: http://weblogs.asp.net/cibrax/archive/2007/08/29/sending-attachments-with-wcf.aspx

If tweaking the setting more does not help you could proceed by using what works:

Split up your large files into several chunks (300MB or less) that you know the framework can manage. Then set up a session within which you will post these chunks and reassemble them on the server. This is how most data transfer protocols do it and it is exactly what's happening lower-down on the OSI stack. You simply need to emulate those strategies to get past this limitation.


I know this is old, but I just wanted to add to this that I was able to figure out exactly what was causing my problem by using the InnerException of the exception that was being thrown.

The outermost exception was too generic, resulting in the message "The underlying connection was closed: The connection was closed unexpectedly."

The inner one was far more descriptive, resulting in the message of "Failed to allocate a managed memory buffer of 1073741824 bytes. The amount of available memory may be low."


Have you tried using chunking channel. It should solve your problem. Check out this MSDN sample: http://msdn.microsoft.com/en-us/library/aa717050.aspx


Take a look at MTOM http://msdn.microsoft.com/en-us/library/ms733742.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消