WCF自定义消息安全
我需要使用轮询技术来通知客户端有关服务器端的更改。所以我尝试使用 DuplexHttpBinding (http://code.msdn.microsoft.com/duplexhttp )。我可以很好地处理非安全消息,但我需要在我的项目中使用消息级安全性(UsernameForCertificate)。好吧,我决定将 SymmetricSecurityBindingElement 添加到绑定集合:
var securityElement = SecurityBindingElement.CreateUserNameForCertificateBindingElement();
collection.Add(securityElement);
然后问题发生了。如果我们使用消息级安全性,则所有消息都包含带有消息签名的安全标头,如下所示:
<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">
....
</o: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.
请建议解决方法,如何在自定义轮询消息中添加适当的安全标头,然后再将其发送到自定义请求通道中。您可以通过之前发布的链接下载源代码,然后尝试将其与 UsernameForCertificate 安全性一起使用来重现该问题。 谢谢。
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">
....
</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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几天后&深入调查我找到了解决方案。看来我们应该在创建自定义 Channel Facroty & 时修改 ChannelProtectionRequirements 。通道侦听器添加加密和我们的自定义消息的签名部分。这是示例:
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: