简体   繁体   中英

Making and using NodeJS's soap client synchronous

A using NodeJs's current soap client to call a soap service function whenever i send an HTTP request to the server.

The Problem is that the request returns before the soap service call finishes, thus returning no data.

The issues here is that the logic is asynchronous yet i need to make it synchronous.

Please kindly direct me to the right solution.

function soap_get_items(req,res){
    var resp = [];

    var soap = require('soap');
    var url = 'http://example.com/example.wsd?singleWsdl';
    var args = {name:"N.Hillary"};

    soap.createClient(url, function(err, client) {
        client.exampleSoapFunction(args, function(err, result) {
            resp = result;
        });
    });

    json_resp = JSON.stringify(resp);
    res.end(json_resp);
}

You don't need to make it synchronous. You just need to just use the callback provided:

soap.createClient(url, function(err, client) {
    client.exampleSoapFunction(args, function(err, result) {
        res.end(JSON.stringify(result));
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM