Skip to main content
edited tags
Link
Will Hartung
  • 119.4k
  • 20
  • 134
  • 209
edited title
Link
Paul Sonier
  • 39.6k
  • 3
  • 81
  • 118

how How to do compression in a restful wcf service returning json

Source Link
odyth
  • 4.3k
  • 3
  • 39
  • 45

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 number = int.Parse(aParameter); number++; return "I added 1 to your number and got " + number; } }