我試圖通過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