none
Microsoft.Samples.GZipEncoder with [WebGet(ResponseFormat = WebMessageFormat.Json) ] ? RRS feed

  • Question

  • With the help of this post I've managed to get WebHttpBinding to work with compression (by means of copy-pasting the code). When pointing the browser to my service method, it downloads a file which I can rename to .zip and decompress, so the compression part works. But I'm not able to use Json instead of XML. When I add the webget ResponseFormat = WebMessageFormat.Json attribute to the service method I just get "[Fiddler] ReadResponse() failed: The server did not return a response for this request." Same if I do

    host.AddServiceEndpoint(typeof(ITest), GetBinding(), "").Behaviors.Add(new WebHttpBehavior {DefaultOutgoingResponseFormat = WebMessageFormat.Json});

    Also the GZipMessageEncoder.WriteMessage isn't even called. What do I need to change in order to get this working with Json ?


    • Edited by Ionel Lescai Wednesday, January 30, 2013 3:44 PM
    Wednesday, January 30, 2013 3:43 PM

Answers

  • As Carlos Figueira kindly pointed out here, "you'd also need to override the MessageEncoder.IsContentTypeSupported to make sure that the gzip encoder also accepts JSON." and optionally add "a message inspector to add a Content-Encoding header, which will allow the browsers to understand the data as-is."

    public override bool IsContentTypeSupported(string contentType)
      {
        return this.innerEncoder.IsContentTypeSupported(contentType);
      }

    • Marked as answer by Ionel Lescai Thursday, January 31, 2013 7:40 AM
    Thursday, January 31, 2013 7:40 AM

All replies

  • Hi,

    >>When I add the webget ResponseFormat = WebMessageFormat.Json attribute to the service method I just get "[Fiddler] ReadResponse() failed: The server did not return a response for this request."

    Is there any inner exception?

    Please try set the response format when define the service contract.

    [WebGet(UriTemplate = "all",ResponseFormat = WebMessageFormat.Json)]
    IEnumerable<Person> GetAll();

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 31, 2013 6:38 AM
    Moderator
  • As Carlos Figueira kindly pointed out here, "you'd also need to override the MessageEncoder.IsContentTypeSupported to make sure that the gzip encoder also accepts JSON." and optionally add "a message inspector to add a Content-Encoding header, which will allow the browsers to understand the data as-is."

    public override bool IsContentTypeSupported(string contentType)
      {
        return this.innerEncoder.IsContentTypeSupported(contentType);
      }

    • Marked as answer by Ionel Lescai Thursday, January 31, 2013 7:40 AM
    Thursday, January 31, 2013 7:40 AM