none
how to retrieve Http request header (Content-Encoding: gzip or deflate) in WCF custom message encoder ? RRS feed

  • Question

  • Hi,

    Currently we are trying to implement, to handle incoming compressed (gzip or deflate) requests by writing custom MessageEncoder for self hosted WCF service.

    But, i can't get access to header Content-Encoding in the following method to decide whether to perform request decompression or not.

    public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType) .

    Any thoughts how to achieve this ?

    Thanks!!!


    • Edited by mohan-s Saturday, December 10, 2016 11:33 AM
    Saturday, December 10, 2016 10:31 AM

Answers

  • Hi Mohan,

    >> Is there any alternative or other place in WCF pipe line, i can read Content-Encoding value before message object has been created ?

    In my option, I am afraid not. As my above reply, we could not get Content-encoding in Message Encoding. Based on below link, there is only ChannelDispatcher, I could not get Content-Encoding at this place.

    # IChannelListener

    https://msdn.microsoft.com/en-us/library/ms734665.aspx

    >> is it right way to proceed by checking "contentType" value available in MessageEncoder ?

    No, Content-Encoding and Content-type are different. Content-Encoding describe whether the data is compressed, Content-Type describe the file formats and format contents.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by mohan-s Wednesday, December 14, 2016 10:35 AM
    Tuesday, December 13, 2016 7:08 AM

All replies

  • Hi mohan-s,

    >>i can't get access to header Content-Encoding in the following method to decide whether to perform request decompression or not.

    Do you mean you want to dynamically compress or not at client side, and decompress or not at service side? As you have found, we could not access “Content-Encoding” in message encoder. Since ReadMessage is before AfterReceiveRequest MessageInspector, it will not work to get “Content-Encoding” in AfterReceiveRequest.

    For a work around, I would suggest you create two endpoints, one is for compressed and another is for uncompressed, write the custom message encoder for compressed endpoint, and then send compressed or uncompressed message from client through different endpoints.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 12, 2016 4:57 AM
  • Hi Edward,

    Thanks for your response.

    Yes, we would like to perform request decompression at service side based on Content-Encoding value and with single endpoint.

    Other options i have read on internet is, implementation of HttpModule and use HttpContext instance to read request header values. but it is possible by enabling AspnetCompatibility and with service hosted in IIS.

    we can't use this option, as we have self hosted service and we can't change hosting environment.

    Is there any alternative or other place in WCF pipe line, i can read Content-Encoding value before message object has been created ? 

    And is it right way to proceed by checking "contentType" value available in MessageEncoder ? If it is fine, which content type can be used for gzip or deflate ?

    Thanks

    Mohan


    • Edited by mohan-s Monday, December 12, 2016 5:44 AM
    Monday, December 12, 2016 5:28 AM
  • Hi Mohan,

    >> Is there any alternative or other place in WCF pipe line, i can read Content-Encoding value before message object has been created ?

    In my option, I am afraid not. As my above reply, we could not get Content-encoding in Message Encoding. Based on below link, there is only ChannelDispatcher, I could not get Content-Encoding at this place.

    # IChannelListener

    https://msdn.microsoft.com/en-us/library/ms734665.aspx

    >> is it right way to proceed by checking "contentType" value available in MessageEncoder ?

    No, Content-Encoding and Content-type are different. Content-Encoding describe whether the data is compressed, Content-Type describe the file formats and format contents.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by mohan-s Wednesday, December 14, 2016 10:35 AM
    Tuesday, December 13, 2016 7:08 AM