I am trying to build a module to handle SOAP functionality for the sake of modularity
I use vpulim/node-soap , allthough it's not relevant for my question:
var soap = require ( "soap" );
function SoapController( url ) {
var self = this; //prevent scope issues
self.GetClient = function () {
soap.createClient(
url , function ( err , client ) {
self.client = client;
console.log( self.client.describe() );
}
)
};
}
module.exports = SoapController;
In my Router:
SoapOb = require ( "./SoapController.js" );
router.get(
'/S' , function ( req , res ) {
var soapC = new SoapOb ( 'http://infovalutar.ro/curs.asmx?wsdl' );
soapC.GetClient();
console.log( soapC );
}
);
Results of conlog: from inside the router:
SoapController { GetClient: [Function] }
And inside the callback of the createClient method:
{ Curs:
{ CursSoap:
{ GetLatestValue: [Object],
getlatestvalue: [Object],
getall: [Object],
getvalue: [Object],
getvalueadv: [Object],
GetValue: [Object],
LastDateInserted: [Object],
lastdateinserted: [Object] },
CursSoap12:
{ GetLatestValue: [Object],
getlatestvalue: [Object],
getall: [Object],
getvalue: [Object],
getvalueadv: [Object],
GetValue: [Object],
LastDateInserted: [Object],
lastdateinserted: [Object] } } }
What I need to acomplish is set the client Instance as a property of the SoapController object so i can access it's methods .
I also tried defining the GetClient method through prototype,but it doesn't work , I get undefined in console
SoapController.prototype.GetClient = function () {
var self = this; //prevent scope issues
soap.createClient(
self.url , function ( err , client ) {
self.client = client;
}
)
};
Please guide me !!!
soap.createClient is an async method. So you have to refactor your getClient method.
now any work you need done must be done inside callback.
);