15

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?

Community
  • 1
  • 1
ush189
  • 1,342
  • 6
  • 22
  • 30

1 Answers1

42

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.

ush189
  • 1,342
  • 6
  • 22
  • 30