简体   繁体   中英

reduce response time from WCF service

My WCF service is returning around 7MB data in string format to client.

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?

 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? Also maybe have a look at iis compression gzip.

I could not find where you have mentioned 'transferMode' in your Custom Binding

<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

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

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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