Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOAP node returns error Target-Namespace "undefined" already in use by another Schema

Tags:

soap

wsdl

node.js

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'),
url = 'https://tracking.russianpost.ru/rtm34?wsdl',
argums={}

soap.createClient(url,argums,function(err, client){
    console.log(client) 
})

but it returns error

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

Can anyone explain what does it meand what should request look like?

like image 674
St.Cremer Avatar asked Sep 22 '16 09:09

St.Cremer


2 Answers

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);
    }
    );
}
like image 171
romkadj Avatar answered Oct 13 '22 19:10

romkadj


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.

like image 45
Rodrigo Avatar answered Oct 13 '22 20:10

Rodrigo