You can achieve it with SoapExtension. You can create class that implements SoapExtension, and register it in web.config.
Sample of soap extension:
public class SecureSoapExtension : SoapExtension
{
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
{
return null;
}
public override object GetInitializer(Type serviceType)
{
return null;
}
public override void Initialize(object initializer)
{
}
public override void ProcessMessage(SoapMessage message)
{
// just for out requests
if (message.Stage == SoapMessageStage.BeforeSerialize)
{
// add needed soap header here
message.Headers.Add(new SecureSoapHeader());
}
}
}
And register in web.config to apply to all web services:
<system.web>
<webServices>
<soapExtensionTypes>
<add type="MyTestMvcApplication.SecureSoapExtension, MyTestMvcApplication, Version=1.0.0.0, Culture=neutral"></add>
</soapExtensionTypes>
</webServices>
</system.web>
Important note: If you are calling your Web Service from an external project, let's say, you have a Class Library where you program all your Proxy handling logic. You must add this to your calling project web.config/app.config too, otherwise it will not work:
<system.web>
<webServices>
<soapExtensionTypes>
<add type="MyTestMvcApplication.SecureSoapExtension, MyTestMvcApplication, Version=1.0.0.0, Culture=neutral"></add>
</soapExtensionTypes>
</webServices>
</system.web>
What kind of makes sense, since it's an Web Service extension it's let up to you "final caller" of the proxy, to decide whether to extend or not the web service request.