我是 SOAP 新手,我需要在这里使用它。
我正在尝试向外部端点发送 SOAP 请求。
为了让它工作,我必须使用证书多次签署 SOAP 请求并对其进行加密。
我使用 WSSecurityCert 函数尝试了 node-soap 包,为其提供私钥、公钥和密码,但这只能让我签名一次。
使用函数setSecurity两次并没有添加两个签名。
我的理解是,soap 包允许您配置所有内容,但最终只创建 XML。这意味着我只能在发送后查看创建的 XML。
我的问题是:
尝试这样做
const soap = require('soap');
const crypto = require('crypto');
// SOAP request payload
const soapRequest = {
// Your SOAP request content
};
function signSoapEnvelope(soapEnvelope) {
// Your signing logic here
const timestamp = new Date().toISOString();
soapEnvelope.Header = {
Timestamp: timestamp,
// Other headers...
};
// You may also want to sign the SOAP body or other parts as needed
// ...
return soapEnvelope;
}
soap.createClient(url, (err, client) => {
if (err) {
console.error(err);
return;
}
let signedSoapRequest = signSoapEnvelope(soapRequest);
signedSoapRequest = signSoapEnvelope(signedSoapRequest); // you could sign it here again
client.MySoapOperation(signedSoapRequest, (err, result) => {
if (err) {
console.error(err);
return;
}
console.log(result);
});
});