I have a generated client from a wsdl without the possibility to Add custom soap headers. I need a soap header lets say "SOAPFIELD1".
I created a Soap Interceptor
SoapHeaderExtension : SoapExtension
Where I intercept the message
public override void ProcessMessage(SoapMessage message)
{
if (message.Stage == SoapMessageStage.BeforeSerialize && message is SoapClientMessage)
{
var clientMessage = message as SoapClientMessage;
AddSoapHeader(clientMessage);
}
}
The add soap header function is like this:
private void AddSoapHeader(SoapClientMessage message)
{
var soapHeader = new CustomHeader
{
SOAPFIELD1 = "abc",
};
message.Headers.Add(soapHeader);
}
Custom Soap Header Class
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.w3.org/2005/08/addressing")]
[System.Xml.Serialization.XmlRootAttribute("*Test123*", Namespace = "http://www.w3.org/2005/08/addressing", IsNullable = false)]
public class CustomHeader : SoapHeader
{
[System.Xml.Serialization.XmlTextAttribute()]
public string SOAPFIELD1 { get; set; }
}
The Header gets updated but instead of
<soap:Header>
<SOAPFIELD1>123</SOAPFIELD1>
</soap:Header>
I get
<soap:Header>
**<Test123 xmlns="http://www.w3.org/2005/08/addressing">**
<SOAPFIELD1>123</SOAPFIELD1>
**</Test123 >**
</soap:Header>
When I remove the Test123 Tag from my custom SoapHeader I get the class name as a structure
<soap:Header>
<CustomHeader xmlns="http://www.w3.org/2005/08/addressing">
<SOAPFIELD1>123</SOAPFIELD1>
</CustomHeader>
</soap:Header>
How can I add a SOAP header directly under the root element soap:Header. I cannot alter the generated classes from the wsdl so I have to use the interceptor
Thank you in advance!