0

Currently, I'm converting datatable to json, it's working fine.

The problem is I want to compress the response. Anyone suggest me. WSID... I want something like that :- https://gist.github.com/chrisnicola/1147568

            using (PooledConnection pooledConnection = AdomdConnectionPool.GetConnection(connstring))
            {
                // Execute the query
                AdomdDataAdapter adapter = new AdomdDataAdapter(q, pooledConnection.Connection);
                DataTable x = new DataTable();
                adapter.Fill(x);

                System.Web.Script.Serialization.JavaScriptSerializer serializer = new

                System.Web.Script.Serialization.JavaScriptSerializer();

                List<object> header = new List<object>();
                List<List<object>> rows = new List<List<object>>();

                foreach (DataColumn col in x.Columns)
                {
                    header.Add(col.ColumnName.Trim());
                }

                foreach (DataRow row in x.Rows)
                {
                    List<object> rowtemp = new List<object>();
                    foreach (DataColumn col in x.Columns)
                    {
                        rowtemp.Add(row[col]); //For Row 24012014----- Rohit
                    }
                    rows.Add(rowtemp);
                }
                return Response.AsJson(new { header, rows });

            }
Rohit Khurana
  • 259
  • 2
  • 7
  • 18
  • Is the call to a webserice / webapi / mvc call? If this is the case it should be possible to add some config, or add gzip to header call – lordkain Jan 24 '14 at 12:40
  • you can enable compression at iis level see http://www.iis.net/configreference/system.webserver/httpcompression and http://www.codeproject.com/Articles/186233/Utilize-gzip-compression-in-IIS Is this also a solution for you – lordkain Jan 24 '14 at 12:45

3 Answers3

1

If you want this done within your Nancy code (as opposed to e.g. IIS configuration) you can create your own custom serializer/deserializer and let Nancy pick it up. see Phillip Haydons blog for information on doing this: http://www.philliphaydon.com/2013/05/nancyfx-revisiting-content-negotiation-and-apis-part-3/

Christian Horsdal
  • 4,838
  • 20
  • 24
0

Why not serialize the initial object (that is large), compress the serialized object, send the compressed string.

You already have the json? Compress it using built in compression routines in .net4.5, and send the compressed string.

On the other side, reverse the process.

I am doing this in one of my projects with normal WCF.

This all assuming you have control over client and server.

Louis van Tonder
  • 3,507
  • 3
  • 26
  • 58
0

Turning on dynamic compression in IIS (despite the warning) is the right thing to do.

Enable IIS7 gzip

These are old posts, but still relevant:

"Turning on Compression is a VERY low effort and VERY high reward thing to do"

and

http://www.codinghorror.com/blog/2004/08/http-compression-and-iis-6-0.html http://www.codinghorror.com/blog/2007/03/reducing-your-websites-bandwidth-usage.html

Community
  • 1
  • 1
Brett
  • 8,276
  • 5
  • 35
  • 51