2011-04-27 24 views
1

我已经在我的代码中启用了流式传输,但仍需要很长时间才能上传大型文件。这里是发生了什么:WCF流式传输花费时间太长

我的WPF代码调用服务来上传文件,但服务调试器很长时间后被击中。对于10 MB文件,大约需要1.07分钟。

以下是代码:

调用代码:

using (System.IO.FileStream stream = new System.IO.FileStream(fileInfo.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) 
      { 
       uploadRequestInfo.FileName = fileInfo.Name; 
       uploadRequestInfo.Length = fileInfo.Length; 
       uploadRequestInfo.FileByteStream = stream; 
       clientUpload.UploadFile(uploadRequestInfo); 
      } 

经营合同:

public partial class RemoteFileInfo { 

     [System.ServiceModel.MessageHeaderAttribute(Namespace="http://tempuri.org/")] 
     public string FileName; 

     [System.ServiceModel.MessageHeaderAttribute(Namespace="http://tempuri.org/")] 
     public long Length; 

     [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)] 
     public System.IO.Stream FileByteStream; 

     public RemoteFileInfo() { 
     } 

     public RemoteFileInfo(string FileName, long Length, System.IO.Stream FileByteStream) { 
      this.FileName = FileName; 
      this.Length = Length; 
      this.FileByteStream = FileByteStream; 
     } 
    } 

的app.config:

 <binding name="BasicHttpBinding_ITransferService" closeTimeout="00:10:00" 
      openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
      messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" 
      useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
       maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <security mode="None"> 
       <transport clientCredentialType="None" proxyCredentialType="None" 
        realm="" /> 
       <message clientCredentialType="UserName" algorithmSuite="Default" /> 
      </security> 
     </binding> 

回答

0

您可以在优化它服务合同级别,由编辑承载WCF服务的Web应用程序的Web.config。

为你指出正确的方向,我将不得不了解的Web服务应用程序的主机等,但它会沿着建立一个自定义的东西线与结合了更多信息:

  • TCP传输
  • 二进制编码