2016-07-25 19 views
1

私はこの記事と非常によく似た問題を抱えています。 SOAP KeyInfo valuesSOAPリクエストで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> 

そして、私はそれから参照しようとしている場所の上にこれを持っています:

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

キー情報作成部でのあらゆる試みが唯一のことができます。ここ

は、期待される出力がどうあるべきかであります私はキーのような項目を挿入してこの部分を埋めることができますが、参考にしたいだけです。このコードは私が作業してきたものですが、私が現時点で望むものを作成していません。

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

ご協力いただきありがとうございました。

答えて

2

このコードを使用すると、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は今正しい「に見える」にもかかわらず、私の問題を解決していないようでした。たぶんそれは誰かを助けるでしょう。

関連する問題