Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize SOAP Header namespace prefixes in WCF

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 ?

like image 464
Cosmin Vană Avatar asked Oct 21 '22 15:10

Cosmin Vană


1 Answers

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.

like image 120
Cosmin Vană Avatar answered Oct 30 '22 14:10

Cosmin Vană