1

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>
CStreet
  • 365
  • 1
  • 5
  • 20
  • I highly recommend https://github.com/strongloop/strong-soap over `node-soap` ... (I used node-soap over a year ago, however, and was met with bugs and incomplete code that made it impossible to use for my project.) – Cody G Aug 30 '18 at 20:40
  • So I tried doing it in strong-soap also per your recommendation. I'm receiving a DestinationUnreachable error. I got this when I was using SoapUI and was able to fix it by add a default wsa:To. I am unsure how to do that in strong-soap though. @CodyG. – CStreet Aug 30 '18 at 20:52
  • There's a lot of options... and I don't know what ws-addressing is https://github.com/strongloop/strong-soap#client `client.addSoapHeader('')` perhaps? – Cody G Aug 30 '18 at 21:21
  • I edited my question to include the strong-soap syntax. I tried adding a default header to the client but got a "Cannot parse response" error. Not sure if that's a good wsa:To header to add or if that's how you add it. Still working on it... – CStreet Aug 31 '18 at 12:46
  • Can you post the request that works for SoapUI? Can you post the actual output from strong-soap? There is a way in strong-soap to output the actual request it is making. I think by looking at these two things we can kind of figure out what's different and hopefully strong-soap will be able to make those changes :) – Cody G Aug 31 '18 at 12:51
  • Edited my question with the request XML from SoapUI, trying to figure out how to get strong-soaps currently – CStreet Aug 31 '18 at 13:00
  • Make sure you're adding that `` to your header too, in strong-soap. I looked at the specification real quick and it looks like it is required – Cody G Aug 31 '18 at 13:02
  • I added the wsa:Action and also edited my question to include the XML request from strong-soap. It looks like the Body is a little different. I think that's auto-generated from strong-soap though. – CStreet Aug 31 '18 at 13:14
  • I think i know the issue. the – CStreet Aug 31 '18 at 13:17
  • use the key `$attributes` in the header object, I think – Cody G Aug 31 '18 at 13:21
  • I see what you're talking about in the docs but am having trouble figure out how to use the syntax – CStreet Aug 31 '18 at 13:28
  • Yeah me too. I'm not sure if you can modify the soapHeader's attributes or not. . . https://github.com/strongloop/strong-soap/blob/d9eab1bfaa15f10eade2e2f4b719c5815bcfb52a/src/soapModel.js – Cody G Aug 31 '18 at 13:36
  • I feel like this should be handled by the wsdl, but maybe not... – Cody G Aug 31 '18 at 13:39
  • Try overriding the namespace perhaps? See an example wsdl options here: https://github.com/strongloop/strong-soap/blob/master/test/request-response-samples/addPets__force_namespaces/wsdl_options.json – Cody G Aug 31 '18 at 13:42
  • Where would this code go? – CStreet Aug 31 '18 at 14:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/179191/discussion-between-cody-g-and-cstreet). – Cody G Aug 31 '18 at 14:09
  • Hi, anyone know the solution to this problem https://stackoverflow.com/questions/54580639/how-to-send-a-soap1-2-request-from-node-js-strong-soap – omega Feb 07 '19 at 19:26
  • how to use WShttpbinding in strong soap – R.Anandan May 23 '19 at 10:17

1 Answers1

1

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);
  })
});
Cody G
  • 8,368
  • 2
  • 35
  • 50