How to pass Authentication Header to node-soap

5.1k views Asked by At

I am trying to use a wsdl service as a client but I cannot find how to set some headers.

The reason I need this is because the wsdl I am trying to use requires the username and password via the headers. this is wsdl

>    POST /Service.asmx HTTP/1.1
>             Host: 210.12.155.16
>             Content-Type: text/xml; charset=utf-8
>             Content-Length: length
>             SOAPAction: "http://yyyy.com:1002/apability"
>             
>             <?xml version="1.0" encoding="utf-8"?>
>             <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>         xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
>               <soap:Header>
>                 <AuthHeader xmlns="http://yyyy.com:1002/">
>                   <UserName>string</UserName>
>                   <Password>string</Password>
>                 </AuthHeader>
>               </soap:Header>
>               <soap:Body>
>                 <sale xmlns="http://yyyy.com:1002/">
>                   <BID>string</BID>
>                   <Amount>string</Amount>
>                   </sale>
>               </soap:Body>
>             </soap:Envelope>

and this is code :

   var args={BID:"123",Amount : "10000"};

      var AuthHeader = {
                "UserName" : user,
                "Password" : pass
                };
            soap.createClient(url,function(error,client){
            client.addSoapHeader(AuthHeader);   

              client.sale(args,function(error,result){
              console.log(error);

            });

i have to send authentication in header but it doesn't work
i thing soapHeader's var is wrong . what would i do to solve authentication problem ? thanks a lot

2

There are 2 answers

0
sevdanlito On

i found answer

var AuthHeader = {AuthHeader: {
            "UserName" : user,
            "Password" : pass,

            }
0
David Hackro On

You can less try sending your header in this way

var Autentication ='<AuthHeader xmlns="http://yyyy.com:1002/"><UserName>user</UserName><Password>pass</Password></AuthHeader>'

Add header

client.addSoapHeader(Autentication)

Good Luck