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();