【发布时间】:2014-02-25 01:54:39
【问题描述】:
我写过一种在 wcf here 生成的 SOAP 消息中自定义命名空间和命名空间前缀的方法。
但是,为了自定义消息的 SOAP 标头,我找不到合适的方法在 Message 类中进行覆盖。
我想发出这条信息:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<h:Protocol xmlns="http://www.xyz.de/Protocol" xmlns:h="http://www.xzy.de/Protocol">
<version>IFD_1.4</version>
</h:Protocol>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
</s:Body>
</s:Envelope>
看起来像这样:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<if:Protocol xmlns="http://www.xyz.de/Protocol" xmlns:if="http://www.xzy.de/Protocol">
<version>IFD_1.4</version>
</if:Protocol>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
</s:Body>
</s:Envelope>
不同的是,第一个标头的命名空间是“if”而不是“f”。
有没有办法使用带有自定义 Message 类的自定义 MessageFormatter 来做到这一点?
【问题讨论】:
-
为什么要关心前缀?
-
通常我不会。但有时我们需要使用新技术“重写”旧服务并支持老客户。虽然新客户端不会关心前缀,但旧客户端已经手动实现了与soap或xml无关的解析算法(他们将其解析为字符串并从中获取他们想要的内容,搜索诸如“if:协议”)
标签: c# wcf messagecontract