简体   繁体   English

减少WCF服务的响应时间

[英]reduce response time from WCF service

My WCF service is returning around 7MB data in string format to client. 我的WCF服务正在以字符串格式向客户端返回大约7MB的数据。

Client has to wait for the response. 客户必须等待响应。

What appropriate bindings that need to modified in config file or any other method which will reduce the response time from WCF Service? 需要在配置文件或任何其他方法中修改哪些适当的绑定,这些绑定将减少WCF服务的响应时间?

 public string GetData() //Without compression
    {
        return File.ReadAllText("SampleDB");
    }


    private string GetDataforCompression() //with compression
    {
       string data=File.ReadAllText("SampleDB");
       Compress(data);

    }

    public static string Compress(string ToCompress)
    {
        var bytes = Encoding.UTF8.GetBytes(ToCompress);

        using (var msi = new MemoryStream(bytes))
        using (var mso = new MemoryStream())
        {
            using (var gs = new DeflateStream(mso, CompressionMode.Compress))
            {

                CopyTo(msi, gs);
            }

            return Convert.ToBase64String(mso.ToArray());
        }
    }

    public static void CopyTo(Stream src, Stream dest)
    {
        byte[] bytes = new byte[4096];

        int cnt;

        while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0)
        {
            dest.Write(bytes, 0, cnt);
        }
    }

I tried sending the data in compressed form and decompressing at the client end but there was'nt significant variation in response time.Below is client side config file 我尝试以压缩形式发送数据并在客户端进行解压缩,但是响应时间没有明显变化。下面是客户端配置文件

 <customBinding>
        <binding name="httpbinarybinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
          <binaryMessageEncoding>
            <readerQuotas maxDepth="4194304" maxStringContentLength="65536000" maxArrayLength="4194304" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />
          </binaryMessageEncoding>
          <httpTransport maxReceivedMessageSize="65536000"  maxBufferSize="65536000" />
        </binding>
      </customBinding>

That's quite a lot of data to send down the line at one time can you not build in paging in your method / web application? 一次要发送大量的数据,您不能在方法/ Web应用程序中建立分页吗? Also maybe have a look at iis compression gzip. 也可以看看iis压缩gzip。

I could not find where you have mentioned 'transferMode' in your Custom Binding 我找不到您在自定义绑定中提到“ transferMode”的地方

<binding name="TransferService"
   maxReceivedMessageSize="2147483647"
   maxBufferSize="2147483647" transferMode="Streamed" >

Streaming will help you to pass your data in chunks. 流式传输将帮助您分块传递数据。 This will help to you manage user response or at least will help in showing progress bar. 这将帮助您管理用户响应,或者至少将有助于显示进度栏。

Please check following links for details: 请检查以下链接以获取详细信息:

http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTP and http://msdn.microsoft.com/en-us/library/aa717050.aspx http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTPhttp://msdn.microsoft.com/en-us/library/aa717050.aspx

Sometimes, knowing datalength may be required for processing data @client side. 有时,在客户端处理数据可能需要知道数据长度。 You may expose it using message contract. 您可以使用消息合同公开它。 http://social.msdn.microsoft.com/Forums/en/wcf/thread/472a7b38-f4fe-420e-85be-ae9c744a94a7 http://social.msdn.microsoft.com/Forums/en/wcf/thread/472a7b38-f4fe-420e-85be-ae9c744a94a7

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM