0

我正在编写一个代码,它将使用 WCF 将选定的文件上传到某个服务器。我正在使用.Net 4.0。我有一个带有文件上传控件的 aspx 页面。在用户浏览文件并单击保存的位置,我将这些文件(以字节读取,然后转换为 base64)保存在会话对象中。还有一个按钮叫做上传。当我点击上传时,我正在调用 WCF 服务并从会话中传递对象。以下是我来自客户端的绑定配置

<i>   
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_DefaultService" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" bypassProxyOnLocal="false" 
             transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
             maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

      <reliableSession ordered="true" inactivityTimeout="00:20:00" enabled="false" />
       <security mode="Message">
        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
</i>

并从服务器跟随一个

<i>
<wsHttpBinding>
<binding name="WSHttpBinding_DefaultService" closeTimeout="0:20:00"
  openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
  bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
  messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
  allowCookies="false">
  <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
    maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
  <reliableSession ordered="true" inactivityTimeout="00:20:00"
    enabled="false" />
  <security mode="Message">
    <message clientCredentialType="Windows" negotiateServiceCredential="true"
      algorithmSuite="Default" />
  </security>
</binding>
</wsHttpBinding>
</i>  

我也对 httpruntime 进行了修改

<i> <httpRuntime requestValidationMode="2.0"  executionTimeout="90" maxRequestLength="2097151"/></i>

问题是每当我尝试选择总大小大于 2.5 MB 的多个文件时,我的对象没有被传输到 WCF,它会抛出错误

<i>The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. >>>> The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. >>>> Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. >>>> An existing connection was forcibly closed by the remote host >>>>     </i>

所以我需要做什么?我正在尝试使用 wsHttpBinding 找到解决方案,所以有什么建议吗?

4

1 回答 1

1

在您的 httpRuntime 配置中,该属性maxRequestLength="2097151"指示最大请求大小约为 2.1 MB。增加它应该会增加您的最大文件大小。

对于较大的文件,您可能希望创建某种流式实现,因此您不需要受 maxRequestLength 属性的限制。

于 2013-09-24T11:08:14.027 回答