如何将参数传递给nodejs中的node-soap

问题描述 投票:1回答:1

我想使用节点肥皂将请求发送到SOAP Web服务,但是出现此错误。

D:\Projects\node-sms-webservice\node_modules\soap\lib\wsdl\index.js:541
                if (typeof value === 'object' && value.hasOwnProperty(this.options.attributesKey)) {
                                                       ^

TypeError: Cannot read property 'hasOwnProperty' of null
    at WSDL.objectToRpcXML (D:\Projects\node-sms-webservice\node_modules\soap\lib\wsdl\index.js:541:56)
    at Client._invoke (D:\Projects\node-sms-webservice\node_modules\soap\lib\client.js:329:33)
    at Client.enqueue (D:\Projects\node-sms-webservice\node_modules\soap\lib\client.js:189:21)
    at D:\Projects\node-sms-webservice\controllers\smscontroller.js:187:16
    at D:\Projects\node-sms-webservice\node_modules\soap\lib\soap.js:84:9
    at WSDL.callback (D:\Projects\node-sms-webservice\node_modules\soap\lib\soap.js:42:17)
    at D:\Projects\node-sms-webservice\node_modules\soap\lib\wsdl\index.js:130:23
    at WSDL._processNextInclude (D:\Projects\node-sms-webservice\node_modules\soap\lib\wsdl\index.js:1057:20)
    at WSDL.processIncludes (D:\Projects\node-sms-webservice\node_modules\soap\lib\wsdl\index.js:146:14)
    at D:\Projects\node-sms-webservice\node_modules\soap\lib\wsdl\index.js:87:19
    at process._tickCallback (internal/process/next_tick.js:61:11)

[我使用了类似其他代码的代码来向服务器发送请求,但我认为参数存在问题。

const soap = require('soap')
/*
SOME CODE
*/
let arguments = {
        'domain': process.env.API_DOMAIN,
        'messageBodies': ['Test Alert'],
        'recipientNumbers': '98936xxxxxx',
        'senderNumbers': process.env.API_SMS_NUMBER
}
/*
SOME CODE
*/
soap.createClient(url, function(err, client) {   
        // Set Basic Authentication Header
        client.setSecurity(new soap.BasicAuthSecurity(username, password));        
        client.enqueue(arguments, function(err, result, rawResponse, soapHeader, rawRequest ) {
            console.log(result)            
        });
});

此外,我使用SoapUI工具来了解有关我调用的方法的更多信息,这是结果。

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://magfa.com/soap/SOAPSmsQueue" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <soapenv:Header/>
   <soapenv:Body>
      <soap:enqueue soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <domain xsi:type="xsd:string">magfa</domain>
         <messageBodies xsi:type="soap:ArrayOf_xsd_string" soapenc:arrayType="xsd:string[]"/>
         <recipientNumbers xsi:type="soap:ArrayOf_xsd_string" soapenc:arrayType="xsd:string[]"/>
         <senderNumbers xsi:type="soap:ArrayOf_xsd_string" soapenc:arrayType="xsd:string[]"/>
         <encodings xsi:type="soap:ArrayOf_xsd_int" soapenc:arrayType="xsd:int[]"/>
         <udhs xsi:type="soap:ArrayOf_xsd_string" soapenc:arrayType="xsd:string[]"/>
         <messageClasses xsi:type="soap:ArrayOf_xsd_int" soapenc:arrayType="xsd:int[]"/>
         <priorities xsi:type="soap:ArrayOf_xsd_int" soapenc:arrayType="xsd:int[]"/>
         <checkingMessageIds xsi:type="soap:ArrayOf_xsd_long" soapenc:arrayType="xsd:long[]"/>
      </soap:enqueue>
   </soapenv:Body>
</soapenv:Envelope>

我上网冲浪,发现了Node-soap: How to create a complex message with specific attributes?问题,并按照此问题中的说明更改了论点,但出现了同样的错误。

请您让我知道如何解决此错误。

谢谢

node.js soap soapui soap-client
1个回答
0
投票

我通过使用axios库发送原始请求解决了我的问题。

let msg = 'SOME STRINGS'
let mobs = [
   'xxxxxxxx',
   'xxxxxxxx'
]

let xml = 
    '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://magfa.com/soap/SOAPSmsQueue" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
    +   '<SOAP-ENV:Body>'
    +       '<ns1:enqueue>'
    +           '<domain xsi:type="xsd:string">'+API_DOMAIN+'</domain>'
    +           '<messageBodies SOAP-ENC:arrayType="xsd:string[1]" xsi:type="SOAP-ENC:Array">'
    +               '<item xsi:type="xsd:string">'+msg+'</item>'
    +           '</messageBodies>'
    +           '<recipientNumbers SOAP-ENC:arrayType="xsd:string['+mobs.length+']" xsi:type="SOAP-ENC:Array">'
    mobs.forEach((mob, ind) => {
        xml +=      '<item xsi:type="xsd:string">'+mob+'</item>'
    })
    xml +=
                '</recipientNumbers>'
    +           '<senderNumbers SOAP-ENC:arrayType="xsd:string[1]" xsi:type="SOAP-ENC:Array">'
    +               '<item xsi:type="xsd:string">'+API_SMS_NUMBER+'</item>'
    +            '</senderNumbers>'
    +           '<encodings xsi:nil="true" xsi:type="SOAP-ENC:Array" />'
    +           '<udhs xsi:nil="true" xsi:type="SOAP-ENC:Array" />'
    +           '<messageClasses xsi:nil="true" xsi:type="SOAP-ENC:Array" />'
    +           '<priorities xsi:type="SOAP-ENC:Array" />'
    +           '<checkingMessageIds xsi:nil="true" xsi:type="SOAP-ENC:Array" />'        
    +       '</ns1:enqueue>'
    +    '</SOAP-ENV:Body>'
    + '</SOAP-ENV:Envelope>'



    axios.post(API_BASE_URI,
        xmls
    , {
        headers: {
            'Content-Type': 'text/xml',
            'SOAPAction': ''
        },
        auth: {
            username: API_USER,
            password: API_PASS
        }
    })
    .then(function (response) {
        console.log(response)
    })
    .catch(function (error) {
        console.log(error)
    });   
© www.soinside.com 2019 - 2024. All rights reserved.