使用wcf传输5兆字节的文件

时间:2011-08-16 12:35:10

标签: c# wcf

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

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

这是我的服务器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,   Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089`

有什么想法吗?

4 个答案:

答案 0 :(得分:3)

答案 1 :(得分:3)

在Web.config

中的maxRequestLength部分设置httpRuntime

HttpRuntime configuration element

答案 2 :(得分:2)

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

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

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

该值以KB为单位。

答案 3 :(得分:0)

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