SOAP节点返回错误Target-Namespace“undefined”已被另一个Schema使用

时间:2016-09-22 09:10:37

标签: node.js soap wsdl

我正在尝试为俄语帖子写一个客户端来跟踪。它使用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

任何人都可以解释它是什么以及请求应该是什么样的?

4 个答案:

答案 0 :(得分:5)

<强>解决即可。问题的解决方法。 首先使用修改后的原始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);
    }
    );
}

答案 1 :(得分:2)

我通过仅定义了一个模式标记来解决,例如:

自:

<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>

要:

<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>

问候。

答案 2 :(得分:2)

虽然上面的解决方案确实有效,但由于它无法达到WSDL的全部目的,因此它是一个糟糕的解决方案。 SoapUI可以很好地与我正在使用的服务配合使用,并且该工具也应该可以。

最后我通过在第826行之后添加以下行来更新node_modules\soap\lib\wsdl\elements.js中的节点肥皂代码来解决了这个问题:var targetNamespace = child.$targetNamespace;

if (!targetNamespace && child.includes && child.includes.length === 1) {
    targetNamespace = child.includes[0].namespace;
}

如果您有一个架构元素,其中唯一的一个子元素是import元素,则此方法有效(请参见下面的示例)。如果维护者愿意,可以尝试获得PR批准。

示例:

<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>

有关原始TS代码,请参见git repo:https://github.com/.../node-soap/.../elements.ts#L826

答案 3 :(得分:1)

我遇到了同样的问题,但还没解决。

版本: “肥皂”:“^ 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!

更新:WSDL不包含targetNamespace。如何解决这个问题?我可以以某种方式使用WSDL选项吗?