使用 Strong-Soap 对 Node 进行简单的 SOAP 调用

Simple SOAP call with Node using Strong-Soap

我正在尝试调用在我的 SOAP 服务中创建的一个简单方法 returns "Hello, World!"。我已经能够使用 SoapUI 成功调用此方法,所以我知道它有效。

目前,打印出来的只是一个空对象。我碰壁了,我不确定自己做错了什么。任何帮助都会很棒!

这是我的:

"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
    })
});

这是 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>

这是来自 Strong-Soap

的 xml 请求
<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>

您可以在 strong-soap 中像这样添加 headers...可能有更好的方法来添加 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);
  })
});