Why is a message in WCF seemingly always in SOAP format?

别说谁变了你拦得住时间么 提交于 2019-12-11 09:57:32

问题


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?


回答1:


It is because all bindings you mentioned are designed to use SOAP protocol. They are using either TextMessageEncoder or BinaryMessageEncoder and both these work with SOAP envelopes (except the situation where you use TextMessageEncoder in custom binding with MessageVersion set to None).

The only out-of-the box binding allowing other message formats is WebHttpBinding which uses WebMessageEncoder supporting both XML and JSON.



来源:https://stackoverflow.com/questions/10024367/why-is-a-message-in-wcf-seemingly-always-in-soap-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!