gpt4 book ai didi

node.js - 使用 Strong-Soap 通过 Node 进行简单 SOAP 调用

转载 作者:太空宇宙 更新时间:2023-11-04 00:06:19 24 4
gpt4 key购买 nike

我正在尝试调用在 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>

最佳答案

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

关于node.js - 使用 Strong-Soap 通过 Node 进行简单 SOAP 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52104489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com