我试图通过ASP.NET Web窗体上传大文件(高达200MB)并将它们存储在数据库中。我能够使用FileUpload控件上传大文件,并且我已经在SQL Server中将字段设置为VarBinary(MAX)FileStream以在外部存储文件。我想将使用WCF服务上传的文件传输到数据库,这是我卡住的地方。我遇到的唯一问题是当我尝试从后面的代码将文件流式传输到WCF服务时。使用WCF和ASP.NET Web窗体传输大文件
设置:在ASP.NET应用程序 客户端的web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFileTransfer" maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
transferMode="Streamed" messageEncoding="Mtom"
sendTimeout="24.20:31:23.6470000" receiveTimeout="24.20:31:23.6470000">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxDepth="2147483647" maxStringContentLength="2147483647"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:25333/FileTransfer.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IFileTransfer" contract="FileTransfer.IFileTransfer"
name="BasicHttpBinding_IFileTransfer" />
</client>
</system.serviceModel>
在WCF应用程序服务器的web.config
<system.serviceModel>
<services>
<service name="Ward.POC1.FileStream">
<endpoint address="ep1" binding="basicHttpBinding" contract="WcfServiceHost.IFileTransfer">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
transferMode="Streamed" messageEncoding="Mtom"
sendTimeout="24.20:31:23.6470000" receiveTimeout="24.20:31:23.6470000">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxDepth="2147483647" maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
我用transferMode =“Streamed”,具有以下合约定义:
[ServiceContract]
public interface IFileTransfer
{
[OperationContract]
Stream GetFile(Guid fileId);
[OperationContract]
void AddFile(Stream fileStream);
}
取决于在配置设置中,我不是得到下面的异常变化:
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '24.20:31:23.6100000'.
或
WCF The remote server returned an error: (400) Bad Request.
谁能为我提供指导转移ASP之间上传大文件.NET和另一个使用WCF的托管应用程序?我正在尝试使用Streaming。如果任何人有优雅的解决方案使用二进制数组/分块,那么它的欢迎。
那些真的需要使用专为文件传输设计的协议传输的文件,可能是FTP? – 2011-06-14 07:02:05
Web应用程序不打算上传1GB文件。在现实世界中,这将非常糟糕。如果你想分块,你将不得不为此编写Silverlight组件。 – 2011-06-14 07:23:56
用于上传的大文件在我的项目中并不常见。用户愿意等待上传完成,我唯一的问题是将上传的文件传输到WCF服务主机。 – rageit 2011-06-14 20:17:53