我曾经写过一篇文章,介绍了如何自定义wcf生成的SOAP消息中的命名空间和命名空间前缀,链接在这里。
但是,我找不到在Message类中覆盖以便自定义消息的SOAP头部的适当方法。
我想要让这条消息变成:
<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”。
是否可以使用自定义的MessageFormatter和自定义的Message类来完成此操作?