首页 > 解决方案 > 如何修复使用 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 属性吗?

标签: node.jssoapnode-soapwsse

解决方案


推荐阅读