-->

为什么SOAP格式是WCF的消息似乎永远?(Why is a message in WCF seem

2019-10-16 14:24发布

我已经通过实施实现在WCF消息督察IDispatchMessageInspector

把一个破发点这种方法...

public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
    // Impementation
}

......我可以看看request对象,看看里面是什么。

显然,我不明白WCF不够,因为无论端点绑定我用(basichttp,nettcp和netpipe)内部的消息在SOAP格式如总是表示

<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
    <s:Header>
        -- headers --
    </s:Header>
    <s:Body>
        -- body --
    </s:Body>
</s:Envelope>

这是因为请求对象上做的ToString()仅仅代表SOAP格式的消息?

我想到,使用另一种协议例如netTcp将导致不同的消息有效载荷。

也可以说,我想代表JSON格式的我怎么会去这样做我的数据? 或者,我会最终有一个SOAP信封中JSON格式的数据结构?

Answer 1:

这是因为你提到的所有绑定都设计为使用SOAP协议。 他们使用的是TextMessageEncoderBinaryMessageEncoder与SOAP信封两种工作(除非你使用的情况TextMessageEncoder定制与结合MessageVersion设置为None )。

唯一外的所述盒结合允许其他消息格式是WebHttpBinding其使用WebMessageEncoder支持XML和JSON。



文章来源: Why is a message in WCF seemingly always in SOAP format?