WCF Streaming 无法传输大文件

标签 wcf streaming file-transfer

我正在制作一个用于传输文件的 WCF 服务。我只有基本的 WCF 了解并遵循 MSDN 教程:WCF Tutorial 我开始使用字节数组来传输文件,但一旦文件变得有点大(100kb 就足够了),它就会因错误请求而失败。 我按照另一个指南更改为流式传输消息,它也适用于小文件,但无法处理较大的文件(例如旧版本)。我怀疑故障出在我的配置文件中,因为 svcutil.exe 生成的配置文件没有说明任何有关流的信息。 这是我的客户 app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IDocPublisher" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="200000000" maxStringContentLength="200000000" maxArrayLength="200000000"
                    maxBytesPerRead="200000000" maxNameTableCharCount="200000000" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService/docPublisher"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDocPublisher"
            contract="IDocPublisher" name="WSHttpBinding_IDocPublisher">
            <identity>
                <userPrincipalName value="Emil-PC\Emil" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>
</configuration>

这是服务器 app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"
                          httpHelpPageEnabled="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="serviceBehavior"
              name="DocPublisher">
    <endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService"
              name="basicHttpStream"
              binding="basicHttpBinding"
              bindingConfiguration="httpLargeMessageStream"
              contract="IDocPublisher" />
    <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"/>
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="httpLargeMessageStream"
                maxReceivedMessageSize="200000000"
                maxBufferSize="200000000"
                transferMode="Streamed"
                messageEncoding="Mtom" />
  </basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>

最佳答案

尝试增加客户端的发送超时和读取器配额,设置服务器端的缓冲区大小。

关于WCF Streaming 无法传输大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15406223/

相关文章:

c# - 保护 wcf 服务的模式和良好实践

javascript - 将部分视频流传输至客户端

android - 通过蓝牙以编程方式传输图像

c# WCF最大字符串内容长度配额

javascript - 访问位于代码后面的变量时的 ASP.NET 编译错误

c# - 从 URL 下载/流式传输文件 - asp.net

java - 数据处理管道的消息传递架构

java - 通过网络发送具有自定义属性的文件

java - 文件传输 RMI

android - Web 服务 session 管理