Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9099905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:44:06+00:00 2026-06-17T00:44:06+00:00

Given a REST service POST call: [WebInvoke] // POST string PostItem(PostItemContract contract); That uses

  • 0

Given a REST service POST call:

 [WebInvoke] // POST
 string PostItem(PostItemContract contract);

That uses a custom gzip encoder within a custom binding (web.config):

  <customBinding>
    <binding name="customHttpGzipBindingConfig">          
      <!-- Normally would use binaryMessageEncoding, textMessageEncoding or webMessageEncoding here  -->          
      <gzipMessageEncoding innerMessageEncoding="webMessageEncoding"/>          
      <httpTransport ...>        
    </binding>        
  </customBinding>     

I get an error:

InvalidOperationException: The incoming message has an unexpected
message format ‘Raw’. The expected message formats for the operation
are ‘Xml’, ‘Json’. This can be because a WebContentTypeMapper has not
been configured on the binding. See the documentation of
WebContentTypeMapper for more details.

Modifying the web config to use webMessageEncoding instead of gzipMessageEncoding clears the error.

So I am thinking I would like to make the custom gzipMessageEncoding behave as if it is a webMessageEncoding:

I first created class GzipWebContentTypeMapper : WebContentTypeMapper where GetMessageFormatForContentType() just returns WebContentFormat.Xml;

Then some mods were made to the encoder which was based on the MSDN sample:

Custom Message Encoder: Compression Encoder

class GZipMessageEncoder : MessageEncoder
{   
   public override bool IsContentTypeSupported(string contentType)
   {
       // A BP here says it is returning true, this is where the
       // custom GetMessageFormatForContentType() is getting called.

       return innerEncoder.IsContentTypeSupported(contentType);
   }     
   // ...
}

public class GZipMessageEncodingElement : BindingElementExtensionElement
{        
    public override Type BindingElementType
    {
       get { return typeof(WebMessageEncodingBindingElement); } // just to see
    }
    public override void ApplyConfiguration(BindingElement bindingElement)
    {                        
        GZipMessageEncodingBindingElement binding = (GZipMessageEncodingBindingElement)bindingElement;

        WebMessageEncodingBindingElement element = new WebMessageEncodingBindingElement();
        // responsible for mapping from Content-Type to WCF xml/json/raw/default formats.
        element.ContentTypeMapper = new GzipWebContentTypeMapper();
        binding.InnerMessageEncodingBindingElement = element;                              
    }
    // ...
}

The debugger shows that:

GzipWebContentTypeMapper is indeed getting called and returning WebContentFormat.Xml;

GZipMessageEncoder.IsContentTypeSupported is returning true.

Explicitly setting the format does not work either (?):

[WebInvoke(RequestFormat=WebMessageFormat.Xml)] 
string PostItem(PostItemContract contract);

Within the web.config, I tried adding a webMessageEncoding before/after the custom gzip encoder but it did not help.

Any ideas what happens after the GZipMessageEncoder.IsContentTypeSupported returns true?

Where would the result of the GzipWebContentTypeMapper (which is successfully returning WebContentFormat.Xml) be stored and how could it be getting disregarded?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:44:07+00:00Added an answer on June 17, 2026 at 12:44 am

    The problem was that the ContentType was not being passed to the innerEncoder within the encoder.

    That is where a message.Property[] is added to the message with key

    WebBodyFormatMessageProperty.Name 
    

    and value

    new WebBodyFormatMessageProperty(WebContentFormat).  
    

    It was adding “Raw” because it did not know what content type it was reading.

    Added contentType argument here:

    class GZipMessageEncoder : MessageEncoder
    {
       // ...
       ReadMessage(ArraySegment<byte> buffer, ...)  
       { 
          //...
          _innerEncoder.ReadMessage(decompressedBuffer, bufferManager, **contentType**);
       }
    
       ReadMessage(Stream stream, ...)
       { 
          //...
          _innerEncoder.ReadMessage(stream, maxSizeOfHeaders, **contentType**);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a REST service that I'm trying to call. It requires something similar
I am dealing with a REST-service that, depending on the information given to it
Given that an input String may be specified as follows: read(xpath(‘...’)) or xpath(‘...’) or
We have a given REST interface: POST /calculation <data>abc</data> This calculation can be implemented
Given this service: POST /hotel HTTP/1.1 <hotel> <a>aaa</a> <b>bbb</b> <c>ccc</c> </hotel> HTTP/1.1 201 CREATED
I created a WCF service, that returns some data and also allow to post
I am trying to set up a simple WCF REST service that we will
Let's say I have built a REST service for making notes that looks something
There is a self hosted WCF REST service, need to send an xml post
I have a REST service (Play Framework 2.0 w/Scala) that receives messages via a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.