在WCF中自定义SOAP Header名称空间前缀 [英] Customize SOAP Header namespace prefixes in WCF

查看:308
本文介绍了在WCF中自定义SOAP Header名称空间前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一种在wcf 此处生成的SOAP消息中自定义名称空间和名称空间前缀的方法. a>.

I have wrote about a way to customize namespaces and namespace prefixes in a SOAP message generated by wcf here.

但是,我无法在Message类中找到适当的方法来覆盖它,以自定义消息的SOAP标头.

However, I can't find a proper method to override in the Message class in order to customize the SOAP headers of the messages.

我要发出此消息:

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

The difference is that the namespace of the first header is "if" instead of "f".

有没有办法使用带有自定义Message类的自定义MessageFormatter?

Is there any way to do this using a custom MessageFormatter with a custom Message class ?

推荐答案

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

The solution I found is to derive from MessageHeader class and use it in my custom Message class (see link from question to see how I used the custom Message class to customize the envelope and body start tag).

准备就绪后,我将使用完整的示例来更新答案.

I will update the answer with a full example once it will be ready.

如果对此有不同的解决方案,请将其发布为更简单的答案,它将在不破坏wcf功能的情况下起作用.

If you have different solutions for this, please post it as the simpler answer which works without breaking the functionality of wcf will be selected.

这篇关于在WCF中自定义SOAP Header名称空间前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆