制作和使用 NodeJS 的 soap 客户端同步
Making and using NodeJS's soap client synchronous
每当我向服务器发送 HTTP 请求时,使用 NodeJs 当前的 soap 客户端调用 soap 服务函数。
问题是 soap 服务调用完成之前的请求 returns,因此没有返回任何数据。
这里的问题是逻辑是异步的,但我需要使其同步。
请指导我找到正确的解决方案。
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);
}
您不需要使其同步。您只需要使用提供的回调:
soap.createClient(url, function(err, client) {
client.exampleSoapFunction(args, function(err, result) {
res.end(JSON.stringify(result));
});
});
每当我向服务器发送 HTTP 请求时,使用 NodeJs 当前的 soap 客户端调用 soap 服务函数。
问题是 soap 服务调用完成之前的请求 returns,因此没有返回任何数据。
这里的问题是逻辑是异步的,但我需要使其同步。
请指导我找到正确的解决方案。
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);
}
您不需要使其同步。您只需要使用提供的回调:
soap.createClient(url, function(err, client) {
client.exampleSoapFunction(args, function(err, result) {
res.end(JSON.stringify(result));
});
});