I\'m trying to write a client for russian post to get track. It uses SOAP WSDL. I\'m to get at least client object.
\'use strict\'
let soap=require(\'soap\
I solved by defined only one schema tag, example:
From:
<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>
To:
<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:import namespace="http://www.russianpost.org/RTM/DataExchangeESPP/Data"
schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=2"/>
<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=3"/>
<xsd:import namespace="http://russianpost.org/sms-info/data"
schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=4"/>
<xsd:import namespace="http://russianpost.org/operationhistory/data"
schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=5"/>
<xsd:import namespace="http://russianpost.org/operationhistory"
schemaLocation="https://tracking.russianpost.ru/rtm34?xsd=6"/>
</xsd:schema>
</types>
Regards.
I got the same problem but haven't solved it.
Version: "soap": "^0.19.0"
Target-Namespace "undefined" already in use by another Schema!
Target-Namespace "undefined" already in use by another Schema!
/Users/andreas/scm/todoListApi/node_modules/soap/lib/wsdl.js:481
this.element = schema.elements[nsName.name];
^
TypeError: Cannot read property 'elements' of undefinedTarget-Namespace "undefined" already in use by another Schema!
Update: the WSDL does not contain targetNamespace. How to work around that? Can I use the WSDL Options somehow?
While the above top solution does work, it's a poor solution since it defeats the whole purpose of WSDLs. SoapUI works fine with the service I'm using and this tool should be able to as well.
I ended up solving this by updating the node-soap code in node_modules\soap\lib\wsdl\elements.js
by adding the following lines after line 826: var targetNamespace = child.$targetNamespace;
:
if (!targetNamespace && child.includes && child.includes.length === 1) {
targetNamespace = child.includes[0].namespace;
}
This works if you have a schema element where the only child is an import element (see example below). May try to get a PR approved if the maintainer is up for it.
Example:
<types>
<xsd:schema>
<xsd:import namespace="http://schema.core.datamodel.fs.documentum.emc.com/" schemaLocation="ObjectService_schema1.xsd"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://rt.fs.documentum.emc.com/" schemaLocation="ObjectService_schema2.xsd"/>
</xsd:schema>
</types>
See git repo for original TS code: https://github.com/.../node-soap/.../elements.ts#L826
Solved. Workaround of issue. First instead of their .wsdl file I use modified original wsdl file and store it locally.
workaround of xml file Fixed it by adding into schema targetnNamespace parameter.
<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>
Original wsdl code part
<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>
now to use our wsdl file:
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);
}
);
}