Dynamically add an encrypted WCF message header

We can add a message header to a WCF message by adding a MessageHeader attribute, like this

 [MessageContract]
 public class HelloResponseMessage
 {
     [MessageHeader(ProtectionLevel=EncryptAndSign)]
     public string SSN
     {
         get { return extra; }
         set { this.extra = value; }
     }
 }

First question: how safe is it and does it work for all types of WCF bindings?

and the second question, is it possible to add an encrypted header to all messages and extract a dynamic version of the server from it?

MessageHeader header = MessageHeader.CreateHeader("SessionKey", "ns", _key);
OperationContext.Current.OutgoingMessageHeaders.Add(header);
+5
source share
1 answer

You can use IServiceBehavior, which in turn will use the DispatchMessageInspector.

For the client proxy, you will create an IEndpointBehavior that will use IClientMessageInspector

IClientMessageInspector MessageHeader BeforeSendRequest.

DispatchMessageInspector AfterReceiveRequest .

, , WSDL. , IWsdlExportExtension.

+2

All Articles