0

When my callback function parse the wsdl file and give the response to me I want to show html page in which i want to show list view with parsed data from my node.js request handler.Here is my code,

soap.createClient(AW_URL, function(err, client) {
  if (err) {
    console.log(err.stack);
    return;
  } 
  else {
    client.setSecurity(new soap.WSSecurity(auth.login, auth.key));
    client.ListProviders(function(err, res) {
         if (err) {
              console.log(err.stack);
              return;
         }
         else {
              var pro = res.Providers[1];
              console.log(pro);

         }
    });
  }
});

//var body = html page

    response.writeHead(200, {"Content-Type": "text/html"});
    response.write(body);
    response.end();

so i am stuck with how to wait for the soap client callback function to get the data because before the data come to me html get in-front.Need a help for this.Any suggestion is great help for me.Thanks in advance.

2 Answers 2

1

Program flow in node.js works like:

response.writeHead(200, { "Content-Type": "text/html" });

doSomethingAsync(function (err, res) {
    response.write(res);
    response.end();
});

So, you don't have to call end() immediately. You can call it from any callback, then the behavior will be as expected.

Sign up to request clarification or add additional context in comments.

Comments

0

You haven't actually specified where you want the html to get generated. All the client methods accept a callback (you have incorrectly put the callback into the args object spot for client.ListProviders.

Let's assume you wanted client.ListProviders to execute before your response gets written...

// where is `response` getting set?? it's not in your example
var response;

function callback() {
   // do stuff here
   response.writeHead(200, {"Content-Type": "text/html"});
   response.write(body);
   response.end();
}

soap.createClient(AW_URL, function(err, client) {
   if (err) {
      //errors
   }
   else {
      client.ListProviders({x: 2, y: 4}, callback);
   }
});

However, I'm not really sure what the issue is. Presumably your soap call is going to output some html? So you probably want something more like this:

// where is `response` getting set?? it's not in your example
var response;
var headerHtml = '<h1>Hello World!</h1>';
var footerHtml = '<div>I like swords!</div>';

// create whatever goes above the soap call
response.writeHead(200, {"Content-Type": "text/html"});
response.write(headerHtml);


function callback(err, result) {

   // do some stuff that create's html and call response.write();

   finishPage();
}

function finishPage() {
   response.end(footerHtml);
}

soap.createClient(AW_URL, function(err, client) {
   if (err) {
      //errors
   }
   else {
      client.ListProviders({x: 2, y: 4}, callback);
   }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.