WCF 流式传输花费的时间太长

发布于 2024-11-03 17:27:18 字数 2305 浏览 1 评论 0原文

我已经在代码中启用了流式传输,但上传大文件仍然需要很长时间。发生的情况如下:

我的 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>

I have enabled streaming in my code but still its taking long time to upload large files. Here is what happens :

My WPF code calls the service to upload the file but the debugger on the service is hit after a long time. For 10 MB file, it takes approx 1.07 mins.

Following is the code :

Calling code :

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);
            }

Operation Contract :

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

脱离于你 2024-11-10 17:27:18

您可以通过编辑托管 WCF 服务的 Web 应用程序的 Web.config 在服务合同级别对其进行优化。

为了给您指明正确的方向,我必须了解有关应用程序托管的 Web 服务等的更多信息。但这将类似于构建自定义绑定:

  • TCP 传输
  • 二进制编码

You can optimize it at the Service Contract level, by editing the Web.config of the Web application that hosts the WCF Service.

To point you in the right direction I would have to know a lot more information about the Web Services that the application hosts, etc. But it would be something along the lines of building a custom binding with:

  • TCP Transport
  • Binary Encoding
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文