【问题标题】:Adding KeyInfo reference in SOAP request在 SOAP 请求中添加 KeyInfo 引用
【发布时间】:2016-07-25 18:45:42
【问题描述】:

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

我想在 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>

我确实在上面尝试引用了这个:

<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 部分的尝试都只允许我插入一个项目(如键)来填写此部分,但我只是想要一个参考。这段代码是我一直在使用的,但目前没有创建我想要的。

//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;

感谢您的关注,我们将不胜感激。

【问题讨论】:

    标签: c# xml soap xml-signature


    【解决方案1】:

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

    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 现在“看起来”正确,但这似乎并没有解决我的问题。也许它会帮助别人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-24
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      • 2013-12-21
      • 1970-01-01
      相关资源
      最近更新 更多