1

使用 WCF 上传 50MG 文件的最佳方式是什么?

我以为 MTOM 会自动处理这个问题。
我想我错了...

即使在 LocalHost 上运行也会发生异常
(我假设使用外部 IIS 会更糟糕)。

异常消息:

“接收对http://localhost:7064/DataSyncService.svc的 HTTP 响应时发生错误 。这可能是由于服务端点绑定未使用 HTTP 协议。这也可能是由于 HTTP 请求上下文被中止服务器(可能是由于服务关闭)。有关更多详细信息,请参阅服务器日志。”

服务器配置

    <system.serviceModel>
    <client>
        <remove contract="IMetadataExchange" name="sb" />
    </client>
    <bindings>
        <wsHttpBinding>
            <binding name="DataSyncBinding" messageEncoding="Mtom" maxReceivedMessageSize ="50000000" maxBufferPoolSize="50000000">
                <readerQuotas maxArrayLength="50000000" />
                <security mode="None" />
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="Server.DataSyncServiceBehavior" name="Server.DataSyncService">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="DataSyncBinding" name="DataSyncService"
                      contract="Server.IDataSyncService" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="Server.DataSyncServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>

客户端配置

    <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="DataSyncService" closeTimeout="00:05:00" openTimeout="00:05:00"
                receiveTimeout="00:30:00" sendTimeout="00:30:00" bypassProxyOnLocal="false"
                transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="None">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:7064/DataSyncService.svc"
            binding="wsHttpBinding" bindingConfiguration="DataSyncService"
            contract="DataSyncServiceReference.IDataSyncService" name="DataSyncService" />
    </client>
</system.serviceModel>

提前致谢。

4

1 回答 1

2

如果文件正好是50 MB,那么您的 maxReceivedMessageSize 和 maxArrayLength 设置得太低,因为 50MB 实际上是 50 * 1024 * 1024 = 52428800 字节。此外,maxReceivedMessageSIze 必须考虑消息本身的结构(SOAP 信封等),而不仅仅是数据。

您可以使用流式传输,这是处理大文件的建议方式。不幸的是,它不适用于 wsHttpBinding,您可能需要使用 basicHttpBinding 或 webHttpBinding 之类的东西来启用流式传输。

更多关于流媒体的信息:

http://msdn.microsoft.com/en-us/library/ms733742.aspx

于 2012-03-06T01:51:24.137 回答