Soap request: TypeError: Cannot use 'in' operator to search for 'A' in svcutil.exe

Soap request: TypeError: Cannot use 'in' operator to search for 'A' in svcutil.exe

我正在尝试从 Ubuntu OS 上的 node.js 服务器向 WSDL API 发送请求。我像这样使用 node-soap

'use strict';
const soap = require('soap');

// Other codes ....

soap.createClient( WSDL_URL, function(err, client) {
    if (err) {
        console.log('Client error: ', err);
        return res.status(500).send('Not OK');
    } else if (client){
        client.MyFunction({header: {...headers}}, function(err2, result) {
            console.log('client.lastRequest: ', client.lastRequest);

            if (err2) {
                console.log('Function err: ', err2);
                return res.status(500).send('Not OK')
            } else if (result) {
                console.log('result: ', result);
                return res.status(200).send('GETTest OK!');
            }
        });
    }
});

我在函数调用 (console.log('Function err: ', err2)) 后收到此控制台错误:

{ TypeError: Cannot use 'in' operator to search for 'A' in svcutil.exe
2|MyProject     |     at SAXParser.p.onclosetag (/root/MyProject/node_modules/soap/lib/wsdl/index.js:334:27)
2|MyProject     |     at emit (/root/MyProject/node_modules/sax/lib/sax.js:624:35)
2|MyProject     |     at emitNode (/root/MyProject/node_modules/sax/lib/sax.js:629:5)
2|MyProject     |     at closeTag (/root/MyProject/node_modules/sax/lib/sax.js:889:7)
2|MyProject     |     at SAXParser.write (/root/MyProject/node_modules/sax/lib/sax.js:1436:13)
2|MyProject     |     at WSDL.xmlToObject (/root/MyProject/node_modules/soap/lib/wsdl/index.js:446:11)
2|MyProject     |     at parseSync (/root/MyProject/node_modules/soap/lib/client.js:274:36)
2|MyProject     |     at /root/MyProject/node_modules/soap/lib/client.js:438:24
2|MyProject     |     at Request._callback (/root/MyProject/node_modules/soap/lib/http.js:162:17)
2|MyProject     |     at Request.self.callback (/root/MyProject/node_modules/request/request.js:185:22)
2|MyProject     |     at emitTwo (events.js:126:13)
2|MyProject     |     at Request.emit (events.js:214:7)
2|MyProject     |     at Request.<anonymous> (/root/MyProject/node_modules/request/request.js:1161:10)
2|MyProject     |     at emitOne (events.js:116:13)
2|MyProject     |     at Request.emit (events.js:211:7)
2|MyProject     |     at IncomingMessage.<anonymous> (/root/MyProject/node_modules/request/request.js:1083:12)
.
.
.

当我使用 Wizdler 插件查看请求的可接受结构时,它看起来像这样:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <FunctionName xmlns="http://something.something.com/">
            <header>
                <OtherDataTags xmlns="http://schemas.datacontract.org/2004/07/something.serviceName.Models">[string?]</OtherDataTags>
                <OtherDataTags xmlns="http://schemas.datacontract.org/2004/07/something.serviceName.Models">[string?]</OtherDataTags>
                <OtherDataTags xmlns="http://schemas.datacontract.org/2004/07/something.serviceName.Models">[string?]</OtherDataTags>
            </header>
        </FunctionName>
    </Body>
</Envelope>

但是 lastRequest 的结果是这样的:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:tns="http://something.something.com/" xmlns:q1="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q2="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q3="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q4="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q5="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q6="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q7="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q8="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q9="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q10="http://schemas.datacontract.org/2004/07/something.serviceName.Models" xmlns:q11="http://schemas.datacontract.org/2004/07/something.serviceName.Models">
    <soap:Body>
        <FunctionName xmlns="http://something.something.com/">
            <header>
                <OtherDataTags xmlns:q4="http://schemas.datacontract.org/2004/07/something.serviceName.Models">something</OtherDataTags>
                <OtherDataTags xmlns:q4="http://schemas.datacontract.org/2004/07/something.serviceName.Models">something</OtherDataTags>
                <OtherDataTags xmlns:q4="http://schemas.datacontract.org/2004/07/something.serviceName.Models">something</OtherDataTags>
            </header>
        </FunctionName>
    </soap:Body>
</soap:Envelope>

好的,我找到了解决方案。创建客户端后,您需要像这样设置端点:

'use strict';
const soap = require('soap');

// Other codes ....

soap.createClient( WSDL_URL, function(err, client) {
    if (err) {
        console.log('Client error: ', err);
        return res.status(500).send('Not OK');
    } else if (client){

        client.setEndpoint(serviceURL); // <------ Add this. serviceURL is the WSDL_URL but without '?wdsl' at the end of the URL

        client.MyFunction({header: {...headers}}, function(err2, result) {
            console.log('client.lastRequest: ', client.lastRequest);

            if (err2) {
                console.log('Function err: ', err2);
                return res.status(500).send('Not OK')
            } else if (result) {
                console.log('result: ', result);
                return res.status(200).send('GETTest OK!');
            }
        });
    }
});