从WSE3到WCF:签名SOAP消息 [英] From WSE3 to WCF: Signing a SOAP message

查看:57
本文介绍了从WSE3到WCF:签名SOAP消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我将代码从WSE3迁移到WCF,并且需要一些技巧来说明如何使用X509Certificate2对象实现对SOAP消息进行签名.

I am moving my code from WSE3 to WCF and need a few tips on how to implement signing a SOAP message with a X509Certificate2 object.

旧代码:

X509SecurityToken tok = new X509SecurityToken(cert);
SoapContext cont = cfs.RequestSoapContext;
cont.Security.Tokens.Add(tok);
cont.Security.Elements.Add(new MessageSignature(tok));

"cert"是我的X509Certificate2对象,"cfs"是是我的Web服务客户端对象.在WSE3中,这似乎工作正常,在WCF中该如何做?

"cert" is my X509Certificate2 object and "cfs" is my Web Services client object. This seemed to work fine in WSE3, how to do the same in WCF?

我确实在"System.IdentityModel.Tokens"下找到了X509SecurityToken类.命名空间,还发现有人建议使用"OperationContext.Current".替换"RequestSoapContext";但没有进一步的说明.顺便说一句 正在用代码完成所有操作,因此请不要建议涉及编辑"app.config"的解决方案.文件等.

I did find X509SecurityToken class under the "System.IdentityModel.Tokens" namespace, and also found someone suggesting using "OperationContext.Current" to replace the "RequestSoapContext" but no further instructions. Btw I am doing this all in code, so please don't suggest solutions that involve editing "app.config" file etc.

任何帮助将不胜感激.

推荐答案

我了解您要使用客户端证书身份验证并使用令牌对消息进行签名.在WCF中,您只需将WCF安全性设置为Message,并将ClientCredential设置为Certificate.

I understand that you want to use client certificate authentication and use the token to sign the message. In WCF, you could just set WCF security to Message and set ClientCredential to Certificate.

在客户端,我们需要通过设置ClientBase< T> .ClientCredentials.ClientCertificate.SetCertificate(...)

On client side, we need provide certificate by setting ClientBase<T>.ClientCredentials.ClientCertificate.SetCertificate(...)

如果不需要消息加密,则配置服务协定,设置[ServiceContract(ProtectionLevel = ProtectionLevel.Sign)]

If you donot need message encryption, then config the service contract, set [ServiceContract(ProtectionLevel=ProtectionLevel.Sign)]

有关WCF邮件安全性的详细信息,请参阅

For details about WCF Message Security, please refer to

http://msdn.microsoft.com/en-us/library/ms733137.aspx

谢谢


这篇关于从WSE3到WCF:签名SOAP消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆