我正在编写一个代码,它会使用WCF将所选文件上传到某个服务器。 我正在使用.Net 4.0。 我有一个带有fileupload控件的aspx页面。 用户浏览文件并单击“保存”时,我将在会话对象中保留这些文件(以字节读入,然后转换为base64)。 还有一个名为Upload的按钮。 当我点击上传时,我正在调用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找到解决方案 那么有什么建议吗?
答案 0 :(得分:1)
在httpRuntime配置中,属性maxRequestLength="2097151"
表示最大请求大小约为2.1 MB。增加它应该会增加你的最大文件大小。
对于较大的文件,您可能需要创建某种streaming implementation,因此您不需要受maxRequestLength属性的限制。