views:

272

answers:

1

Hello! I need to use polling technique to notify clients about changes in server-side. So I tried to use DuplexHttpBinding (http://code.msdn.microsoft.com/duplexhttp). I works fine with non-secured messages, but I need to use message-level security in my project (UsernameForCertificate). Ok, I decided to add SymmetricSecurityBindingElement to binding collection:

 var securityElement = SecurityBindingElement.CreateUserNameForCertificateBindingElement();
collection.Add(securityElement);

And then problem happened. If we use message-level security all messages include security-headers with message signature, like this:

<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:s="http://www.w3.org/2003/05/soap-envelope"&gt;
....
</o:Security>

And custom polling messages which are send by custom request channel has no security headers, so exception occurs while sending this message through the channel with message-level security:

System.ServiceModel.Security.MessageSecurityException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
No signature message parts were specified for messages with the 'http://samples.microsoft.com/duplexhttp/pollingAction' action.

Please, advice workaround how to add proper security headers to my custom polling messages before sending them inside custom request channel. You can download source code by the link posted before and simply try to use it with UsernameForCertificate security to reproduce the issue. Thank you.

A: 

After couple of days & deep investigation I found the solution. It seems that we should modify ChannelProtectionRequirements when creation custom Channel Facroty & Channel Listener to add encryption & signature parts to our custom messages. Here is the sample:

 private static void ApplyChannelProtectionRequirements(BindingContext context)
    {
        var cpr = context.BindingParameters.Find<ChannelProtectionRequirements>();
        if (cpr != null)
        {
            XmlQualifiedName qName = new XmlQualifiedName("customHeader", "namespace");
            MessagePartSpecification part = new MessagePartSpecification(qName);
            cpr.IncomingEncryptionParts.AddParts(part, "inctomingAction");
            cpr.IncomingSignatureParts.AddParts(part, "inctomingAction");
            cpr.OutgoingEncryptionParts.AddParts(part, "outgoingAction");
            cpr.OutgoingSignatureParts.AddParts(part, "outgoingAction");
        }
    }
albicelestial