Created
November 14, 2012 12:48
-
-
Save ssboisen/4071919 to your computer and use it in GitHub Desktop.
Silverlight, GZip and ServiceStack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void Application_BeginRequest(object sender, EventArgs e) | |
{ | |
if (this.Request.Url.AbsolutePath.Contains("/api/")) | |
{ | |
this.Request.Filter = new System.IO.Compression.GZipStream(this.Request.Filter, System.IO.Compression.CompressionMode.Decompress, true); | |
this.Response.Filter = new System.IO.Compression.GZipStream(this.Response.Filter, System.IO.Compression.CompressionMode.Compress, true); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GzipJsonServiceClient : JsonServiceClient | |
{ | |
public GzipJsonServiceClient(string baseUri) : base(baseUri) { } | |
public GzipJsonServiceClient(string syncReplyBaseUri, string asyncOneWayBaseUri) : base(syncReplyBaseUri, asyncOneWayBaseUri) { } | |
public override void SerializeToStream(IRequestContext requestContext, object request, Stream stream) | |
{ | |
using (var memStream = new MemoryStream()) | |
{ | |
base.SerializeToStream(requestContext, request, memStream); | |
var zipped = GZipStream.CompressBuffer(memStream.ToArray()); | |
stream.Write(zipped, 0, zipped.Length); | |
} | |
} | |
public override StreamDeserializerDelegate StreamDeserializer | |
{ | |
get { return UnZipper;} | |
} | |
private object UnZipper(Type type, Stream fromStream) | |
{ | |
using (var unzipped = new GZipStream(fromStream, CompressionMode.Decompress)) | |
return base.StreamDeserializer(type, unzipped); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment