Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In node-soap, how can I see/debug the generated XML SOAP request?

Tags:

soap

node.js

I try to use the node-soap module like this:

const soap = require('soap');

soap.createClient('some-wsdl-url', function(err, client) {
    const args = {
        'ValidateCustomerRequest': {
            'memberNumber': 12345
        }
    };

    client.ValidateCustomer(args, function(err, result) {
        console.log(result);
    });
});

Now I get an "invalid format" response from the webservice. To debug this I would very much like to see what the actual XML looks like that is sent to the webservice.

I already tried this one:

require('request').debug = true

... which was suggestes in another SO answer.

But the output is not that helpful:

[ERROR] REQUEST { uri:
  Url { ... },
  method: 'GET',
  headers:
   { 'User-Agent': 'node-soap/0.18.0',
     Accept: 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8',
     'Accept-Encoding': 'none',
     'Accept-Charset': 'utf-8',
     Connection: 'close',
     Host: 'xxx' },
  followAllRedirects: true,
  body: null,
  callback: [Function] }

I don't see my "ValidateCustomerRequest" in there and body is null. Also I'm wondering why method is GET, shouldn't that be POST?

So does this debug output looks normal and/or is there another way to see the created XML request?

like image 857
ush189 Avatar asked Feb 08 '17 16:02

ush189


People also ask

How do I find SOAP requests?

SOAP messages are transported by HTTP protocol. To view the HTTP request, click RAW at SoapUI Request window (left side). The Request is posted to the web-server. Hence, the POST method of Http is used.

What is SOAP in node JS?

SOAP is basically an XML based API that existed before the REST API existed. SOAP stands for Simple Object Access Protocol – it's a mostly legacy protocol that was designed for doing remote api requests in a language independent way.

How is a SOAP request sent?

You have several options: write a little script in any familiar language, script should connect to specified server and send a POST request with a body as mentioned in your message. use some of existing programs to do that for you.


1 Answers

I overlooked this bit of the documentation:

Client.lastRequest - the property that contains last full soap request for client logging

You can log this within the callback of the webservice call. So above code will look like this:

const soap = require('soap');

soap.createClient('some-wsdl-url', function(err, client) {
    const args = {
        'ValidateCustomerRequest': {
            'memberNumber': 12345
        }
    };

    client.ValidateCustomer(args, function(err, result) {
        console.log(result);
        console.log('last request: ', client.lastRequest) // <-- here
    });
});

This will output the generated XML request.

like image 57
ush189 Avatar answered Sep 20 '22 12:09

ush189