2

I have some sample code that looks like the following:

var soap = require('soap');
var url  = "http://www.example.com?wsdl";

var soapHeader = "<AuthHeader>...</AuthHeader>";

soap.createClient(url, function(err, client){
  client.addSoapHeader(soapHeader);

  var args = {
       'arg1': 1
    }
  };

  client.SomeMethod(args, function(err, result){
   if(err){

    throw err;

   }
   console.log(JSON.stringify(result));
  });
});

The problem is the request is failing due to either an incorrect header or arguments I'm passing. It would be much easier to debug if I could see the entirety of the request body. How is that done?

randombits
  • 47,058
  • 76
  • 251
  • 433
  • tcpdump, wireshark, fiddler, hand-made proxy – Alex Blex Oct 13 '17 at 16:47
  • 1
    @AlexBlex There should be a way built into the client to see the request body, but I can't find it. – randombits Oct 13 '17 at 17:52
  • 3
    There is [client.lastRequest](https://github.com/vpulim/node-soap#clientlastrequest---the-property-that-contains-last-full-soap-request-for-client-logging), or you can listen on events like `request` to get the payload before it is sent. I believe non-intrusive sniffer is a bit simpler and reliable for your needs though. – Alex Blex Oct 15 '17 at 23:42
  • more, client has lastResponse and both Headers for lastResponse and lastRequest – lyolikaa Feb 04 '20 at 12:46

1 Answers1

5

Not sure if this is still relevant to you, but here goes:

var soap = require('soap');
var url  = "http://www.example.com?wsdl";

var soapHeader = "<AuthHeader>...</AuthHeader>";

soap.createClient(url, function(err, client){
  client.addSoapHeader(soapHeader);

  var args = {
       'arg1': 1
    }
  };

  client.SomeMethod(args, function(err, result){
   if(err){

    throw err;

   }
   console.log('last request: ', client.lastRequest);
   console.log(JSON.stringify(result));
  });
});

The extra console.log statement with "lastRequest" will show the XML request that is being sent, which can be used for debugging. Hope this helps.