【问题标题】:Simple SOAP call with Node using Strong-Soap使用 Strong-Soap 与 Node 进行简单的 SOAP 调用
【发布时间】:2018-08-30 19:57:35
【问题描述】:

我正在尝试调用在我的 SOAP 服务中创建的返回“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>

【问题讨论】:

  • 我强烈推荐github.com/strongloop/strong-soap 而不是node-soap ...(然而,我在一年前使用过node-soap,遇到了错误和不完整的代码,这使得我无法使用项目。)
  • 所以我也按照您的建议尝试在强肥皂中进行操作。我收到 DestinationUnreachable 错误。我在使用 SoapUI 时得到了这个,并且能够通过添加默认的 wsa:To 来修复它。我不确定如何在强肥皂中做到这一点。 @CodyG。
  • 有很多选择......我不知道ws-addressing是什么github.com/strongloop/strong-soap#clientclient.addSoapHeader('&lt;yourxml&gt;')也许?
  • 我编辑了我的问题以包含强肥皂语法。我尝试向客户端添加默认标头,但出现“无法解析响应”错误。不确定这是否是一个好的 wsa:To 标头添加,或者您是否是这样添加的。还在努力……
  • 你能发布适用于 SoapUI 的请求吗?您可以发布强肥皂的实际输出吗? strong-soap 中有一种方法可以输出它发出的实际请求。我认为通过查看这两件事,我们可以找出不同之处,并希望 strong-soap 能够做出这些改变:)

标签: node.js soap node-soap strong-soap


【解决方案1】:

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

【讨论】:

  • strong-soap 是否支持 wshttpbinding ?
  • 我要问一个新问题。
  • 有没有办法将“To”设置为默认值
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多