WsseHeaderToken wsseHeader = new WsseHeaderToken(); // Add Timestamp element to the WSSE Header 添加时间戳元素 TsToken ts = wsseHeader.AddTimestamp(60); // Sign the timestamp element with default certificate使用缺省证书对时间戳元素签名 WsToken[] sigTokens = new WsToken[] {ts}; wsseHeader.AddSignature(sigTokens); // Encrypt the signature and body elements with default key 使用缺省的密钥加密签名及主体中元素 WsTokenRef[] encTokens = new WsTokenRef[] { new DSigTokenRef(), new SoapBodyRef() }; wsseHeader.AddEncryption(encTokens); wsseHeader.PRocessHeader(); Element soap = wsseHeader.GetSoapEnvelope();
// Reference and read WSSE header with null actor 使用null操作器引用和读取WSSE 头部 WsseHeaderRef ref = WsseHeaderRef.CreateFromFile(filename, null); WsseHeaderToken wsseHeader = ref.GetWsseHeader(); // Reference a sample element in the retrieved header 引用已读取头部包含的一个示例元素 SampleTokenRef sampleRef = new SampleTokenRef(wsseHeader,"sample1"); SampleToken sample = sampleRef.GetSampleToken(); // Create a new WSSE header and add the element 生成新的安全头部信息并添加元素 WsseHeaderToken wsseNew = new WsseHeaderToken(); wsseNew.InsertToken(sample); // Add sample element's processing in the new WSSE header 在生成的头部中处理示例元素 SampleProcessor sampleProcessor = new SampleProcessor(); sampleProcessor.SetReplaceTokens(true); sampleProcessor.AddToken(sample); wsseNew.AddProcessor(sampleProcessor); wsseNew.ProcessHeader(); Element soap = wsseNew.GetSoapEnvelope();