node-soap初始化报错:Cannot read properties of undefined (reading 'elements')
Node-soap客户端初始化报错:TypeError: Cannot read properties of undefined (reading 'elements')
我在基于node-soap库搭建SOAP客户端时遇到初始化失败的问题,代码实现如下:
class DreamloveAdapter extends Adapter { soapClient: soap.Client | null = null; constructor(id: string) { super(id); } initialize = async () => { if (!process.env.DREAMLOVE_WEBSERVICE_URL) throw new Error("Missing DREAMLOVE_WEBSERVICE_URL env variable"); try { this.soapClient = await soap.createClientAsync( "https://store.dreamlove.es/webservices/orderservice_wsdl.php" ); } catch (error) { console.error(error); throw new Error("Error initialising Dreamlove adapter"); } }; };
注:SOAP客户端会通过环境变量传入服务地址,已添加对应的缺失校验。
每当实例化该类并调用initialize方法时,都会触发以下错误:
TypeError: Cannot read properties of undefined (reading 'elements') at MessageElement.postProcess (webpack-internal:///(rsc)/./node_modules/soap/lib/wsdl/elements.js:530:35) at OperationElement.postProcess (webpack-internal:///(rsc)/./node_modules/soap/lib/wsdl/elements.js:776:21) at PortTypeElement.postProcess (webpack-internal:///(rsc)/./node_modules/soap/lib/wsdl/elements.js:815:19) at BindingElement.postProcess (webpack-internal:///(rsc)/./node_modules/soap/lib/wsdl/elements.js:858:22) at ServiceElement.postProcess (webpack-internal:///(rsc)/./node_modules/soap/lib/wsdl/elements.js:928:29) at eval (webpack-internal:///(rsc)/./node_modules/soap/lib/wsdl/index.js:84:44) at WSDL._processNextInclude (webpack-internal:///(rsc)/./node_modules/soap/lib/wsdl/index.js:1089:20) at WSDL.processIncludes (webpack-internal:///(rsc)/./node_modules/soap/lib/wsdl/index.js:140:14) at eval (webpack-internal:///(rsc)/./node_modules/soap/lib/wsdl/index.js:74:18) at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
已完成的排查步骤:
- 排除Node.js版本问题:使用Node v20环境调用已知可用的WSDL时,代码可正常运行;
- 排除SSL问题:使用自签名证书搭建测试服务器后,问题依旧;
- 已联系服务方开发者,但对方无法定位问题原因。
我怀疑服务方提供的WSDL格式存在问题,但对SOAP/WSDL了解有限无法确认,希望能明确该错误的触发原因,以及针对该WSDL的解决方向。
内容的提问来源于stack exchange,提问作者Dominic Sore
相关产品推荐
相关产品推荐

