使用wcf服务传输大文件

时间:2014-07-02 09:06:43

标签: wcf

我想运行WCF服务文件传输

我的问题是在发送大文件时,我收到此异常消息ProtocolException

  

(413)请求实体太大。

这是我的配置

我在互联网上找到了这个代码,所以我不确定它是否有效

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <system.web>
            <compilation debug="true" targetFramework="4.0" />
            <httpRuntime executionTimeout="999999" maxRequestLength="2097151" />
        </system.web>
        <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior>
                        <serviceMetadata httpGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
            <services>
                <service name="BasicHttpBinding_ITransferService">
                    <endpoint
                         binding="basicHttpBinding" contract="ITransferService"
                         bindingConfiguration="BasicHttpBinding_ITransferService"   />
                </service>
            </services>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_ITransferService" closeTimeout="04:01:00"
                         openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
                         allowCookies="false" bypassProxyOnLocal="false"
                         hostNameComparisonMode="StrongWildcard"
                         maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
                         maxReceivedMessageSize="2147483647"
                         messageEncoding="Mtom" textEncoding="utf-8"
                         transferMode="Streamed"
                         useDefaultWebProxy="true">
                        <readerQuotas maxDepth="128"
                            maxStringContentLength="2147483647" maxArrayLength="2147483647"
                            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    </binding>
                </basicHttpBinding>
            </bindings>
        </system.serviceModel>
        <system.webServer>
            <modules runAllManagedModulesForAllRequests="true"/>
            <directoryBrowse enabled="true"/>
        </system.webServer>
    </configuration>

1 个答案:

答案 0 :(得分:0)

我会尝试逐个发送文件。

你的API可能是这样的:

byte[] GetFile (string FileID, int startByte, int bytes, ...)

这样你就可以在出错后轻松恢复转移,你不必担心超时等等。