【问题标题】:Transferring 5 megabytes file using wcf使用 wcf 传输 5 兆字节的文件
【发布时间】:2011-08-16 12:35:10
【问题描述】:

我正在尝试使用 wcf 来传输大于 5 兆的文件。(我现在不能使用流式传输,它需要对正在运行的代码进行重大更改)。

我将服务器和客户端配置为最大设置,但我仍然得到最大长度的异常。

这是我的服务器 web.config:

<system.serviceModel>
<diagnostics>
  <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
    logMessagesAtTransportLevel="true" />
</diagnostics>
<services>
    <service name="xxx.xxx.Service">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="xxx"
            contract="xxx.xxx.IService" />
    </service>
</services>
<bindings>
    <basicHttpBinding>
        <binding name="b2bservice" closeTimeout="00:01:00" openTimeout="00:01:00"
            receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            transferMode="Buffered" useDefaultWebProxy="true">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            <security mode="None" />
        </binding>
    </basicHttpBinding>
</bindings>
<client />
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />

这里是客户端 app.config:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="xxx"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
    contract="BService.IBService" name="BasicHttpBinding_IService" />
</client>

我的跟踪记录是:

已超出最大请求长度。
System.ServiceModel.CommunicationException,System.ServiceModel, 版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089`

有什么想法吗?

【问题讨论】:

  • 服务器是IIS,还是你自己的应用程序?

标签: c# wcf


【解决方案1】:
【解决方案2】:

在 Web.config 的 httpRuntime 部分设置 maxRequestLength

HttpRuntime configuration element

【讨论】:

    【解决方案3】:

    您需要通过更改 web.config 中的以下设置来增加最大请求长度

    <configuration>
        <system.web>
            <httpRuntime maxRequestLength="32768" />
        </system.web>
    </configuration>
    

    值以 KB 为单位。

    【讨论】:

      【解决方案4】:

      您可以使用tracing 获取有关您的问题的更多详细信息并修复它或提供使用确切的错误消息。

      【讨论】:

      • 我做到了,我在我的问题中发布了异常
      猜你喜欢
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 2011-01-31
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 2010-10-08
      • 2013-06-13
      相关资源
      最近更新 更多