【问题标题】:npm soap with auth header带有 auth 标头的 npm soap
【发布时间】:2017-11-24 01:06:55
【问题描述】:

我正在尝试使用 npm soap 包创建一系列到远程服务器的端点,我可以通过 angular 4 与之交互。我已经阅读了文档,但我仍然不清楚它的用法。下面是 WSDL。如何创建可用于与以下端点交互的客户端?这是 WSDL。

http://208.180.122.191:8081/niku/wsdl/Query/ts_pending_approvals?tenantId=clarity

我的期望是我应该得到以下回复:

var soap = require('soap');
var url = 'http://208.180.122.191:8081/niku/wsdl/Query/ts_pending_approvals?tenantId=clarity';
var args = {Username: "jdoe", Password: "*******"};
soap.createClient(url, function(err, client) {
client.Login(args, function(err, result) {
        console.log(result);
    });
});

当我调用 console.log(client.describe()) 时,我得到以下信息:

{ ts_pending_approvalsQueryService:
  { ts_pending_approvalsQueryService:
   { Query: [Object],
     Login: [Object],
     WrappedLogin: [Object],
     Logout: [Object] } } }

但是,当我调用 login 并传递用户名和密码时,我得到了未定义。使用 SoapUI,我能够使用以下命令成功完成请求。我的问题是如何在 node.js 中模拟这个。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://www.niku.com/xog/Query">
 <soapenv:Header/>
 <soapenv:Body>
    <quer:Login>
       <quer:Username>jdoe</quer:Username>
       <quer:Password>******</quer:Password>
    </quer:Login>
 </soapenv:Body>
 </soapenv:Envelope>

【问题讨论】:

    标签: node.js soap npm


    【解决方案1】:

    我可以通过设置端点自行解决这个问题,这给了我预期的响应令牌:6312078__98C024DA-25CF-441E-A47B-A84DDE2FF140

    var soap = require('soap');
    var url = 'http://208.180.122.191:8081/niku/wsdl/Query/ts_pending_approvals';
    var args = {Username: "jdoe", Password: "*****"};
    soap.createClient(url, function(err, client) {
       client.setEndpoint("http://208.180.122.191:8081/niku/xog")
       client.Login(args,(error,result)=>{
           if (error) throw error;
           console.log(result)
       })
    });
    

    还值得注意的是,当您使用包并且发送了附加参数时,除了需要多个参数的复杂结构之外,您可能还必须发送映射到 WSDL 中指定命名空间的标头.经过一些试验和错误,我能够弄清楚这一点。请参阅下面的工作示例:

    /////////////////////////////////////////////////////////////////////////////////////////////////////
    // 1TS Open Timesheet
    
    ppmRouter.get("/open_time_sheet",(req,res,next) => {
    
        var resourceid = req.query.param_resourceid
    
        var soap = require('soap');
        var url = config.wsdlQueryPath + 'open_time_sheet';
        var sheader = { Auth: {Username: config.xog_user, Password: config.password}}
        var args = { 
            Query:  {Code: "open_time_sheet"}, 
            Filter: {
                param_resourceid: resourceid
            }
        };
    
        soap.createClient(url, function(err, client) {
            client.addSoapHeader(sheader,"","tns","Auth");
            client.setEndpoint(config.xog_url)
            client.Query(args,(error,result)=>{
                if (error) throw error;
                console.log(result)
                res.send(result)
            })
        });
    
    })
    

    【讨论】:

      猜你喜欢
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      相关资源
      最近更新 更多