node.jssoapnode-soapstrong-soap

Simple SOAP call with Node using Strong-Soap


I'm trying to call a simple method created within my SOAP service that returns "Hello, World!". I've been able to successfully call this method using SoapUI, so I know it works.

Currently, all that's being printed out is an empty object. I have hit a wall an am unsure what I'm doing wrong. Any help would be great!

Here's what I have:

"use strict";

var soap = require('strong-soap').soap;
// wsdl of the web service this client is going to invoke. For local wsdl you can use, url = './wsdls/stockquote.wsdl'
var url = 'https://test-idv.dataventures.com/CP3_WCF_DATA/WCFAccess.svc/mex?wsdl';

var options = {};

soap.createClient(url, options, function (err, client) {
    client.addSoapHeader("<wsa:Action>http://tempuri.org/IWCFAccess/GetOtherData</wsa:Action>");
    client.addSoapHeader("<wsa:To>https://test-idv.dataventures.com/CP3_WCF_DATA/WCFAccess.svc</wsa:To>");
    client.GetOtherData({}, function (err, result, envelope, soapHeader) {
        if (err) {
            throw err;
        }
        console.log(result);
        // Result is a javascript object
        // Envelope is the response envelope from the Web Service
        // soapHeader is the response soap header as a JavaScript object
    })
});

Here's the SoapUI XML:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
    <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
        <wsa:Action>http://tempuri.org/IWCFAccess/GetOtherData</wsa:Action>
        <wsa:To>https://test-idv.dataventures.com/CP3_WCF_DATA/WCFAccess.svc</wsa:To>
    </soap:Header>
    <soap:Body>
        <tem:GetOtherData/>
    </soap:Body>
</soap:Envelope>

Here is the xml request from Strong-Soap

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">  
    <soap:Header>    
        <wsa:Action>http://tempuri.org/IWCFAccess/GetOtherData</wsa:Action>    
        <wsa:To>https://test-idv.dataventures.com/CP3_WCF_DATA/WCFAccess.svc</wsa:To>  
    </soap:Header>  
    <soap:Body>   
        <ns1:GetOtherData xmlns:ns1="http://tempuri.org/"/>  
    </soap:Body>
</soap:Envelope>

Solution

  • You could add the headers like so in strong-soap... there might be a better way to add the xmlns.

    "use strict";
    require('request').debug = true
    var soap = require('strong-soap').soap;
    // wsdl of the web service this client is going to invoke. For local wsdl you can use, url = './wsdls/stockquote.wsdl'
    var url = 'https://test-idv.dataventures.com/CP3_WCF_DATA/WCFAccess.svc/mex?wsdl';
    
    var options = {};
    
    soap.createClient(url, options, function (err, client) {
      client.addSoapHeader(`<wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">http://tempuri.org/IWCFAccess/GetOtherData</wsa:Action>`);
      client.addSoapHeader(`<wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">https://test-idv.dataventures.com/CP3_WCF_DATA/WCFAccess.svc</wsa:To>`);
      client.GetOtherData({}, function (err, result, envelope, soapHeader) {
        console.log('result',result);
        console.log('envelope',envelope);
        if (err) {
          throw err;
        }
        console.log(result);
      })
    });