1

I want to use node-soap to send a request to a SOAP web service but I get this error.

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)

I used a code like the further code to send a request to the server but I think I have problem with my arguments.

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)            
        });
});

In addition to that, I use SoapUI tool to understand more about the method which I called and here is the result.

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

I surfed the net and I found Node-soap: How to create a complex message with specific attributes? qustion and change my argument as mentioned in this question but I get the same error.

Would you please let me know how to fix this error.

Thanks

M. Javad Mohebbi
  • 415
  • 1
  • 3
  • 14

1 Answers1

1

I fixed my problem by sending a raw request using axios library.

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)
    });   
M. Javad Mohebbi
  • 415
  • 1
  • 3
  • 14