gpt4 book ai didi

c# - 在 WCF 中自定义 SOAP header 命名空间前缀

转载 作者:太空狗 更新时间:2023-10-29 23:31:27 24 4
gpt4 key购买 nike

我已经写了关于在 wcf here 生成的 SOAP 消息中自定义 namespace 和 namespace 前缀的方法。 .

但是,我找不到合适的方法来覆盖 Message 类以自定义消息的 SOAP header 。

我要发这条消息:

<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>

区别在于第一个header的命名空间是“if”而不是“f”。

有没有办法使用带有自定义 Message 类的自定义 MessageFormatter 来做到这一点?

最佳答案

我找到的解决方案是派生自 MessageHeader 类并在我的自定义 Message 类中使用它(请参阅问题中的链接以了解我如何使用自定义 Message 类来自定义信封和正文开始标记)。

准备好后,我会用完整示例更新答案。

如果您对此有不同的解决方案,请发布它,因为将选择在不破坏 wcf 功能的情况下工作的更简单的答案。

关于c# - 在 WCF 中自定义 SOAP header 命名空间前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21495857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com