5

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 ?

Zword
  • 6,605
  • 3
  • 27
  • 52
Cosmin Vană
  • 1,562
  • 12
  • 28
  • Why do you care about the prefixes? – John Saunders Feb 01 '14 at 09:01
  • 2
    Usually I don't. But sometimes we're required to "rewrite" old services using new technology and also to support old clients. While the new clients won't care about prefixes, the old clients have manually implemented parsing algorithms which have nothing to do with soap or xml (they parse it just as string and take what they want from it, searching for strings like "if:Protocol") – Cosmin Vană Feb 01 '14 at 09:11

2 Answers2

3

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.

Cosmin Vană
  • 1,562
  • 12
  • 28
0

You could use a custom MessageEncoder and in the ReadMessage and WriteMessage methods you can do whatever you like with the xml.

Matt
  • 224
  • 1
  • 5