node.js - 如何修复使用 node-soap 在 NodeJS 中调用 SOAP Web 服务的“属性 xmlns:wsse 无效”错误
问题描述
我正在尝试调用需要通过 X509 证书进行身份验证的 Web 服务。我正在使用 Node.js 和 node-soap 模块,成功获得了 WSDL。
但是,当我尝试构建带有 Signature 标记的 SOAP 信封时,我从服务器收到以下错误:
属性“prefix="xmlns",localpart="wsse",rawname="xmlns:wsse"" 的值无效。带前缀的命名空间绑定不能为空。
我试图修改传递给底层库(xml-crypto)的现有前缀。
这是我的代码:
var privateKey = fs.readFileSync(process.env.KEYFILE);
var publicKey = fs.readFileSync(process.env.CERTFILE);
var password = ''; // optional password
var options = {
mustUnderstand: 1,
signerOptions: {
existingPrefixes: {
'wsse': "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
}
},
};
var wsSecurity = new soap.WSSecurityCert(privateKey, publicKey, password, options);
const endpoint = process.env.ENDPOINT;
soap.createClientAsync(endpoint).then(client => {
client.setSecurity(wsSecurity);
return client.wiOperationAsync({ ... })
})
但是,错误仍然存在,我得到一个 SOAP 请求正文,如下所示:
<KeyInfo>
<wsse:SecurityTokenReference
xmlns:wsse="">
<wsse:Reference URI="#x509-1639ca80191641b9bd804497cfcef0b5" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
</wsse:SecurityTokenReference>
</KeyInfo>
有什么想法可以避免那个空的 mlns:wsse 属性吗?
解决方案
推荐阅读
- microsoft-file-explorer - 如何使我的桌面应用程序能够在文件资源管理器中使用打开方式打开
- powershell - 修改 Stack Overflow 上的 PowerShell 脚本
- android-studio - 在 Android 中更改 API 级别
- python - pandas:通过将 DataFrame 行与另一个 DataFrame 的列进行比较来创建新列
- vercel - Vercel 无服务器功能已超时错误
- django - 如何将存储库中的特定 django 文件夹部署到 azure 应用服务?
- ios - UITableView 自定义单元格高度不起作用
- angular - Angular 2 和 RxJS:Subject.next 在某些情况下不起作用
- sbt-native-packager - 在 maven repo 上找不到 native-package-manager 和 sbt-git 插件
- python - 使用 Selenium 访问日期元素