简体   繁体   English

同步制作和使用NodeJS的Soap客户端

[英]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. 每当我向服务器发送HTTP请求时,使用NodeJs当前的Soap客户端调用Soap服务功能。

The Problem is that the request returns before the soap service call finishes, thus returning no data. 问题在于请求在soap服务调用完成之前返回,因此不返回任何数据。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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