7

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?

4 Answers 4

7

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);
    }
    );
}
Sign up to request clarification or add additional context in comments.

5 Comments

works for my only adding the "targetNamespace=" to the wsdl and save a local copy of that in the root path of the app
Firts open in my browser the wsdl url and save as wsdl file, after I modify in a text editor thats it.
Hi how update soap server "wsdl file" from another server when i can't access server ?
@SoheilTayyeb if you can access the "wsdl file" via a web browser, just save the file on your computer and update it.
This works so +1, but see my answer below for a solution that doesn't require keeping a local copy of the wsdl.
2

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.

1 Comment

How did you choose which namespace to wrap all of it? ("russianpost.org/custom-duty-info/data" in your case)
2

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

Comments

1

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?

1 Comment

the 'schema' tags have some child tags inside, with attribute 'namespace'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.