在 SOAP 请求中添加 KeyInfo 引用 [英] Adding KeyInfo reference in SOAP request

查看:19
本文介绍了在 SOAP 请求中添加 KeyInfo 引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在这里遇到了与这篇文章非常相似的问题.SOAP KeyInfo 值

So I'm having a very similar issue to this post here. SOAP KeyInfo values

我想在 KeyInfo 中添加一个引用,但似乎无法通过代码找到方法.

I am wanting to add a reference within KeyInfo but can't seem to find a way to do it through code.

以下是预期的输出:

<KeyInfo>
    <wsse:SecurityTokenReference>
        <wsse:Reference URI="#SecurityTest" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
    </wsse:SecurityTokenReference>
</KeyInfo>

而且我确实在上面试图引用的地方有这个:

And I do have this above where it is trying to reference from:

<wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" 
        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" 
        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
        wsu:Id="SecurityTest">Base64CertStuffBlahblah
</wsse:BinarySecurityToken>

每次尝试创建 KeyInfo 部分都只允许我插入一个项目,比如一个键,来填充这部分,但我只想要一个参考.这段代码是我一直在使用的代码,但目前并未创建我想要的代码.

Every attempt at creating the KeyInfo portion only allows me to insert an item, like a key, to fill in this part in but I just want a reference. This code is what I've been working with but is not creating what I want at the moment.

//This creates a X509 clause but it's as far as I've got. 
//The "keyInfoData" needs to be of a different type to allow custom reference?
var signer = new SignedXmlWithId(doc) {SigningKey = Key};
KeyInfo keyInfo = new KeyInfo();
KeyInfoX509Data keyInfoData = new KeyInfoX509Data();
keyInfoData.AddCertificate(cert);
keyInfo.AddClause(keyInfoData);
signer.KeyInfo = keyInfo;

感谢您的关注,任何帮助将不胜感激.

Thanks for looking, any help would be appreciated.

推荐答案

所以这段代码让我可以将我想要的内容添加到 KeyInfo 部分.

So this piece of code lets me add what I want into the KeyInfo portion.

KeyInfo keyInfo = new KeyInfo();
XmlElement x = doc.CreateElement("wsse","SecurityTokenReference", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
XmlElement y = doc.CreateElement("wsse","Reference", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
y.SetAttribute("URI","#SecurityTest");
y.SetAttribute("ValueType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3");
x.AppendChild(y);
var keyInfoData = new KeyInfoNode(x);
keyInfo.AddClause(keyInfoData);
signer.KeyInfo = keyInfo;

这会产生以下结果:

<KeyInfo>
    <wsse:SecurityTokenReference>
        <wsse:Reference URI="#SecurityTest" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" />
    </wsse:SecurityTokenReference>
</KeyInfo>

这似乎并没有解决我的问题,尽管 SOAP 现在看起来"是正确的.也许它会帮助别人.

This didn't seem to fix my issue though the SOAP now "looks" correct. Maybe it will help someone else.

这篇关于在 SOAP 请求中添加 KeyInfo 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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