I have implemented a message inspector in WCF by implementing IDispatchMessageInspector
.
Putting a break point on this method...
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
// Impementation
}
... I can look at the request
object to see what is inside.
Clearly I dont understand WCF enough because whatever endpoint binding I use (basichttp, nettcp and netpipe) the message inside is always represented in SOAP format e.g.
<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Header>
-- headers --
</s:Header>
<s:Body>
-- body --
</s:Body>
</s:Envelope>
Is this because doing a .ToString() on the request object just represents the message in SOAP format?
I imagined that using another protocol e.g. netTcp would result in a different message payload.
Also lets say I wanted to represent my data in JSON format how would I go about doing this? Or would I end up with JSON formatted data structures inside a SOAP envelope?
It is because all bindings you mentioned are designed to use SOAP protocol. They are using either
TextMessageEncoder
orBinaryMessageEncoder
and both these work with SOAP envelopes (except the situation where you useTextMessageEncoder
in custom binding withMessageVersion
set toNone
).The only out-of-the box binding allowing other message formats is
WebHttpBinding
which usesWebMessageEncoder
supporting both XML and JSON.