Search code examples
node.jssoapnode-soap

Connecting to a web service using SOAP


I am currently working on a node based application trying to make a request to a SOAP based service. I am making use of the node-soap module to work through this. https://github.com/vpulim/node-soap

Currently i have the following implementation

var soap = require('soap');
var url = 'http:/xxxx/xxxx/xxxx?WSDL';
var appKey = 'ABYRCEE';
var xml = {
    appKey: appKey,
    mac: 'xxxxxxxx'
}

soap.createClient(url, function(err, client){
    //console.log('Client:', client);
    client.getAllDocsisVideoInfo(xml, function(err, result){
       if(err){
           console.log(err);
       }
    });
});

For the service to respond, i have a sample request in xml format, as the following

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:doc="http://xxx.xxx.com">

   <soapenv:Header/>

   <soapenv:Body>

      <doc:getAllDocsisVideoInfo>

         <appKey>"appKey"</appKey>

         <mac>xxxxxxx</mac>

      </doc:getAllDocsisVideoInfo>

   </soapenv:Body>

</soapenv:Envelope>

As you can see from the above that i have to pass in appKey and mac values and upon a successful request this will send back successful response in xml format with the appropriate response.

I am able to see client object return back with the appropriate functions, but upon calling the client.getAllDocsisVideoInfo(....), i seem to see the following error

S:Client: Cannot find dispatch method for {}getAllDocsisVideoInfo

I am not sure of the why? Is it because of the way i am passing in the xml object, how do i pass in the sample request?


Solution

  • So after spending hours on this and banging my head, i was able to get a successful response by overriding the namespace prefix, by removing the namespace prefix.

    For example, the following object needed to be passed as

    var xml = {
        ':appKey': appKey,
        ':mac': 'xxxxxxxx'
    }
    

    Instead

    var xml = {
        appKey: appKey,
        mac: 'xxxxxxxx'
    }
    

    This piece of the node-soap documentation [https://github.com/vpulim/node-soap#overriding-the-namespace-prefix][1] helped in figuring out the issue.