I have a Meteor method inside that am calling the soap function.
Meteor is executing all the statement before its getting the response from soap client.
So i am getting a result as undefined.
I want to promise the soap execution before executing other statements in the method.
createSoapConnection(){
var Soap = require('soap');
var url = 'https://xxxxxx/index.php/api/v2_soap/?wsdl';
var args = {username: 'xxxxxx', apiKey: 'xxxxxx'};
let client = Soap.createClient(url, function(err, client){
let result = client.login(args, function(err, result) {
let sessionId = result.loginReturn.$value;
console.log(sessionId);
return {
conn: client,
sessionId: sessionId
};
});
});
}
I am calling this method by this meteor method.
addsoapmessage(){
let a = Meteor.call("createSoapConnection");
console.log(a);
}
In the console am getting undefined as a result. after that the session ID is getting printed. How do i solve this?
meteor add zardak:soap
Install this package in root of application folder. then try with those following codes.
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
try {
var client = Soap.createClient(url);
var result = client.MyFunction(args);
return result; // or send this result to the function where ever you want.
}
catch (err) {
if(err.error === 'soap-creation') {
console.log('SOAP Client creation failed');
}
else if (err.error === 'soap-method') {
console.log('SOAP Method call failed');
}
}
You can do any soap api calls with these functions. for more details visit : https://atmospherejs.com/zardak/soap