How to do compression in a restful wcf service returning json
I have a restful WCF service that is returning JSON. I was wondering how I could compress the data? I read that HTTP has support for compression, I just don't know how to turn it on. I was sort of hoping it would be a method decoration. Below is the code for my webservice. Idealy looking for some code examples or articles to read, I've been googling and so far have come up empty, my google-foo is weak today.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class FooService
{
[WebInvoke(UriTemplate = "Foo", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
public string Foo(string aParameter)
{
int numbe开发者_如何学JAVAr = int.Parse(aParameter);
number++;
return "I added 1 to your number and got " + number;
}
}
You can add GZip compression to WCF based REST enabled service.
Here's how.
- WCF REST Compression
- WCF REST (WebHttpBinding compatible ) client gzip compression
- How to add GZIP compression to a .NET WCF REST POX client
Try this C# compression, it works like a champ at doing in-memory compression! And it is Free!! http://www.codeproject.com/KB/cs/IMCompressor.aspx
精彩评论