davidx1
davidx1

Reputation: 3673

NodeJS - How to get the HTTP header of a SOAP webservice's response

When consuming a SOAP webservice in NodeJS with the 'soap' package. Like so:

var soap = require('soap');
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
clientsoap.createClient(url, function(err, client) {
    client.MyFunction(args, function(err, result, raw, soapHeader) {
        console.log(result);
    });
});

How do I get the HTTP header of the response to MyFunction? Specifically, I want the Cookie parameter inside the HTTP Header.

Is this something Node/Express can do? Or Is there another package I need to achieve this?

Thanks in advance.

Upvotes: 1

Views: 2252

Answers (2)

Rob Clarke
Rob Clarke

Reputation: 21

The NodeJS soap module stores the last response headers against the client when invoking a method, so just access it in your callback:

var soap = require('soap');
var url = 'http://somewhere.com?wsdl';
var args = {name: 'value'};
soap.createClient(url, function(err, client) {
  client.myFunction(args, function(err, result) {
    console.log(client.lastResponseHeaders);        
  });
});

Upvotes: 2

Chris D
Chris D

Reputation: 1

I ran into the same issue and have been working on it for a while now. I have made some progress to where I can see the cookies but they aren't coming through exactly as I expected. I'm not sure if I'm doing something wrong or it's specific to the service WSDL I'm trying to hit. But here's my solution...

soap.createClient(pathOrUrlToWSDL, function(err, client) {
    client.myFunction(args, function(err, result, raw, soapHeader) {
        console.log(err, result, raw, soapHeader);
    });

    // -- should reach the response before the callback in client.myFunction()
    client.on('response', function(envelope, message) {
        // -- couldn't find documentation on this function, so I just named the variables 'envelope' and 'message'
        console.log(message.headers);
    });
});

Upvotes: 0

Related Questions