我正在尝试为俄罗斯帖子写一个客户端来跟踪.它使用SOAP WSDL.
我至少得到客户端对象.
我至少得到客户端对象.
'use strict' let soap=require('soap'),url = 'https://tracking.russianpost.ru/rtm34?wsdl',argums={} soap.createClient(url,argums,function(err,client){ console.log(client) })
但它返回错误
Target-Namespace "undefined" already in use by another Schema! Target-Namespace "undefined" already in use by another Schema! Target-Namespace "undefined" already in use by another Schema! Target-Namespace "undefined" already in use by another Schema! Target-Namespace "undefined" already in use by another Schema! /home/st.cremer/Сайты/get-posts/node_modules/soap/lib/wsdl.js:481 this.element = schema.elements[nsName.name]; ^ TypeError: Cannot read property 'elements' of undefined
任何人都可以解释它是什么以及应该要求的样子?
解决方法
解决了.问题的解决方法.
首先,我使用修改后的原始wsdl文件而不是他们的.wsdl文件,并将其存储在本地.
首先,我使用修改后的原始wsdl文件而不是他们的.wsdl文件,并将其存储在本地.
xml文件的变通方法通过添加到模式targetnNamespace参数来修复它.
<definitions ... xmlns:myns="http://russianpost.org/operationhistory"> <types> <xsd:schema targetNamespace="http://www.russianpost.org/custom-duty-info/data"> <xsd:import namespace="http://www.russianpost.org/custom-duty-info/data" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=1"/> </xsd:schema> <xsd:schema targetNamespace="http://www.russianpost.org/RTM/DataExchangeESPP/Data"> <xsd:import namespace="http://www.russianpost.org/RTM/DataExchangeESPP/Data" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=2"/> </xsd:schema> <xsd:schema targetNamespace="http://schemas.xmlsoap.org/soap/envelope/"> <xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=3"/> </xsd:schema> <xsd:schema targetNamespace="http://russianpost.org/sms-info/data"> <xsd:import namespace="http://russianpost.org/sms-info/data" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=4"/> </xsd:schema> <xsd:schema targetNamespace="http://russianpost.org/operationhistory/data"> <xsd:import namespace="http://russianpost.org/operationhistory/data" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=5"/> </xsd:schema> <xsd:schema targetNamespace="http://russianpost.org/operationhistory"> <xsd:import namespace="http://russianpost.org/operationhistory" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=6"/> </xsd:schema> </types> <message name="getOperationHistory" targetNamespace="http://russianpost.org/operationhistory"> <part name="parameters" element="tns:getOperationHistory"/> </message>
原始的wsdl代码部分
<types> <xsd:schema> <xsd:import namespace="http://www.russianpost.org/custom-duty-info/data" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=1"/> </xsd:schema> <xsd:schema> <xsd:import namespace="http://www.russianpost.org/RTM/DataExchangeESPP/Data" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=2"/> </xsd:schema> <xsd:schema> <xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=3"/> </xsd:schema> <xsd:schema> <xsd:import namespace="http://russianpost.org/sms-info/data" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=4"/> </xsd:schema> <xsd:schema> <xsd:import namespace="http://russianpost.org/operationhistory/data" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=5"/> </xsd:schema> <xsd:schema> <xsd:import namespace="http://russianpost.org/operationhistory" schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=6"/> </xsd:schema> </types> <message name="getOperationHistory"> <part name="parameters" element="tns:getOperationHistory"/> </message>
现在使用我们的wsdl文件:
var SoapClient = require('soap'); var options = { 'trace': 1,"overrideRootElement": { "namespace": "myns","xmlnsAttributes": [{ "name": "xmlns:ns2","value": "http://russianpost.org/operationhistory" }] },forceSoap12Headers: true,connection: 'keep-alive','soap_version': 2 }; SoapClient.createClient('./local_wsdl.xml',options,function (err,client) { client.getOperationHistory( { 'ns1:OperationHistoryRequest': { 'ns1:Barcode': trackValue,'ns1:MessageType': 0,'ns1:Language': 'RUS',},'ns1:AuthorizationHeader': { 'ns1:login': login,'ns1:password': password,(err,result) => { if (err) { console.log(err); return; } console.log(result.OperationHistoryData); } ); }