[英]Customize SOAP Header namespace prefixes in WCF
我已经写了一个定制的命名空间和命名空间前缀由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类来做到这一点?
我找到的解决方案是从MessageHeader类派生并在我的自定义Message类中使用它(请参阅问题链接以查看我如何使用自定义Message类来自定义信封和正文开始标记)。
一旦准备就绪,我将用完整的例子更新答案。
如果您有不同的解决方案,请将其发布为更简单的答案,该答案在不破坏wcf功能的情况下将被选中。
您可以使用自定义MessageEncoder,在ReadMessage和WriteMessage方法中,您可以使用xml执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.