I have wrote about a way to customize namespaces and namespace prefixes in a SOAP message generated by wcf here.
However, I can't find a proper method to override in the Message class in order to customize the SOAP headers of the messages.
I want to make this 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>
Look like this:
<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>
The difference is that the namespace of the first header is "if" instead of "f".
Is there any way to do this using a custom MessageFormatter with a custom Message class ?
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.
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.
You could use a custom MessageEncoder and in the ReadMessage and WriteMessage methods you can do whatever you like with the xml.
来源:https://stackoverflow.com/questions/21495857/customize-soap-header-namespace-prefixes-in-wcf