Pedro Felix on Sun, 01 Jul 2012 23:53:30

I have a Service Bus (SB) relaying scenario where I'm using the WCF Web programming model, namely the WebHttpRelayBinding. One of the operations, associated with the POST method, has a Stream parameter to access the HTTP request body. Everything works fine except, when the body media type is "application/json" or "application/xml". Apparently, the WebContentTypeMapper should be used in those situations to force a "raw" format. Unfortunately, this type mapper appears to be ignored when using service bus. Is that so?

I've managed to solve the case of "application/json", by forcing a WebBodyFormatMessageProperty with a message inspector, however I'm unable to solve the "application/xml" case. I think the primary reason is that the wrapped request relayed by SB is different for "application/xml", when compared with all other media types. Any idea on how to solve this?


Arwind - MSFT on Mon, 02 Jul 2012 08:55:49


Try to encode the xml document into a binary stream on the client side and then send to the service. If you don’t want to binary encode it, then you don’t need stream mode at all. Streaming mode allows you to send binary data as is, without encoding it to xml or JSON. That’s the advantage.

Hope this helps.

Pedro Felix on Mon, 02 Jul 2012 13:44:55


Thanks for your response. However:

1) I do not control the clients. They are "generic" HTTP clients that do POST requests using bodies with different media types (e.g. form url encoding, xml, json, image).

2) At the service side, I want to always access the POST body via a stream, independently of the media type.


Arwind - MSFT on Tue, 03 Jul 2012 02:36:56


According to, WebContentTypeMapper works fine in Service Bus. Can you try again?



Pedro Felix on Tue, 03 Jul 2012 21:57:25

Hi again,

Yes, I confirm that the WebContentTypeMapper is *not* called.

I'm using a custom binding built like this

public Binding GetBinding()
            var b = new WebHttpRelayBinding(EndToEndWebHttpSecurityMode.None, RelayClientAuthenticationType.None);
            var elems = b.CreateBindingElements();
            var ee = elems.Find<WebMessageEncodingBindingElement>();
            ee.ContentTypeMapper = new RawContentTypeMapper();
            return new CustomBinding(elems);

If the POST request contains a "application/json" body, then the RawContentTypeMapper *is* called.

However, if the POST request contains a "application/xml" body, then the RawContentTypeMapper *is not* called. In this case, I get the following in the trace log

Incoming message for operation 'Invoke' (contract 'DispatcherService' with namespace '') does not contain a WebBodyFormatMessageProperty. This can be because a WebContentTypeMapper or a WebMessageEncodingBindingElement has not been configured on the binding. See the documentation of WebContentTypeMapper and WebMessageEncodingBindingElement for more details.



Allen Chen - MSFT on Thu, 19 Jul 2012 08:29:45


I remember the service bus does alter the message so I wrote a sample to show how to alter message back before handling data. Not sure whether it still behave the same way now but you may have a look at my sample (mainly pay attention to my custom IDispatchMessageInspector):

Allen Chen [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.