我正在尝试使用一个WSDL服务,发现了node-soap,但是我无法找到如何设置一些头信息。
示例:
header = {
"Username": "foo",
"Password" : "bar"
}
我需要这个是因为我尝试使用头文件传递用户名和密码,以便消费wsdl。提前感谢。
我正在尝试使用一个WSDL服务,发现了node-soap,但是我无法找到如何设置一些头信息。
示例:
header = {
"Username": "foo",
"Password" : "bar"
}
现在可能还没有用,但为了回答这个仍然未解决的问题,以下是方法Client.addSoapHeader的使用方式。根据文档:
Client.addSoapHeader(soapHeader[, name, namespace, xmlns]) - 将 soapHeader 添加到 soap:Header 节点
选项
soapHeader 对象({rootName: {name: "value"}}) 或者严格的 xml 字符串。当第一个参数为对象时,可选择传入下列可选参数:
name 未知参数(可以是一个空字符串)
namespace XML 命名空间前缀
xmlns URI
因此,您需要创建一个对象,并将其传递给此方法,例如:
var soapHeader = {
"Username": "foo",
"Password" : "bar"
};
client.addSoapHeader(soapHeader);
WS-Security
(我不知道,因为我远离 SOAP),那么您需要向作者提出问题,因为根据文档,我看不到设置自定义标头的方法。WS-Security
,请按照README 中的这一部分说明进行操作。soap.createClient(url,
function (err, client) {
if(err){
console.log(err);
} else{
console.log(client.describe())
var soapHeaders = {
'Channel':'PB',
'RqUID':'1987'
}
client.addHttpHeader('<nameH1>', 'valueH1');
client.addHttpHeader('<nameH2>', 'valueH2');
//then, continue calling the soap operation
}
soap = require('soap')
parseString = require('xml2js').parseString
soap.createClient('https://api.bingads.microsoft.com/Api/Advertiser/AdIntelligence/v9/AdIntelligenceService.svc?wsdl', function(err, client) {
var soapHeader = {
'AuthenticationToken': process.argv[2],
'DeveloperToken': process.argv[3],
'CustomerId': process.argv[4],
'CustomerAccountId': process.argv[5]
};
client.addSoapHeader(soapHeader);
client.SuggestKeywordsFromExistingKeywords({Keywords: ["Hello world"]}, function(err, result) {
console.log(result.body);
});
});
这不会起作用。回复是无效的登录凭据。相同的凭据在SOAPUI中可以正常工作。因此,发送登录凭据的格式在其他答案中提到的可能是错误的。
这对我有用。创建客户端方法需要wsdl_header来检索wsdl定义。一旦创建完成,您需要设置基本身份验证安全性。
var url = 'your WSDL url';
var auth = "Basic " + new Buffer("username" + ":" + "password").toString("base64");
soap.createClient( url,{ wsdl_headers: {Authorization: auth} }).then(
function(client){
client.setSecurity(new soap.BasicAuthSecurity('rflhconfort_ws', '6syqxje9'));
client.your_Method(args);
}
我曾经遇到过同样的问题,以下是解决方法: 使用SOAPUI客户端插入数据时,我的WSDL(查看所需字段)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:yourUrn">
<soapenv:Header>
<urn:AuthenticationMethod>
<urn:userName>username</urn:userName>
<urn:password>password</urn:password>
</urn:AuthenticationMethod>
</soapenv:Header>
<soapenv:Body>
<urn:SoapFunctionToCall>
<urn:Field1>Text</urn:Field1>
<urn:Field2>Text</urn:Field2>
<urn:Field3>Text</urn:Field3>
<urn:Field14>Text</urn:Field4>
<urn:Field5>Text</urn:Field5>
<urn:Field6>Text</urn:Field6>
</urn:SoapFunctionToCall>
</soapenv:Body>
</soapenv:Envelope>
以下是我在Node.js中调用的方法:
function createSoapEntry(){
let url = "your wsdl url"
var credentials = {
AuthenticationMethod:{
userName: "username",
password: "password"
}
}
let args = {
Field1:"Text",
Field2:"Text",
Field3:"Text",
Field4:"Text",
Field5:"Text",
Field6:"Text"
}
soap.createClient(url, function (err, client){
client.addSoapHeader(credentials)
client.SoapFunctionToCall(args, function (err, res) {
if (err) {
console.log("Error is ----->" + err)
} else {
console.log("Response is -----> " + res)
}
})
})
}