5

I'm trying to use an xml web service soap client in node and I'm not sure how to add the soap header for my example.

Looking at strong-soap, there is a method addSoapHeader(value, qname, options) but I'm not sure what I need to pass in as qname and options in this case.

My request that I need to send

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aut="http://schemas.foo.com/webservices/authentication" xmlns:hot="http://foo.com/webservices/hotelv3" xmlns:hot1="http://schemas.foo.com/webservices/hotelv3"> <soapenv:Header> <aut:AuthenticationHeader> <aut:LoginName>foo</aut:LoginName> <aut:Password>secret</aut:Password> <aut:Culture>en_US</aut:Culture> <aut:Version>7.123</aut:Version> </aut:AuthenticationHeader> </soapenv:Header> <soapenv:Body> <hot:BookHotelV3> <!--Optional:--> <hot:request> <hot1:RecordLocatorId>0</hot1:RecordLocatorId> <!--Optional:--> <hot1:RoomsInfo> <!--Zero or more repetitions:--> <hot1:RoomReserveInfo> <hot1:RoomId>123</hot1:RoomId> <hot1:ContactPassenger> <hot1:FirstName>Joe</hot1:FirstName> <hot1:LastName>Doe</hot1:LastName> </hot1:ContactPassenger> <hot1:AdultNum>2</hot1:AdultNum> <hot1:ChildNum>0</hot1:ChildNum> </hot1:RoomReserveInfo> </hot1:RoomsInfo> <hot1:PaymentType>Obligo</hot1:PaymentType> </hot:request> </hot:BookHotelV3> </soapenv:Body> </soapenv:Envelope> 

Should value be:

value = { LoginName:'foo', Password:'secret', Culture:'en_US', Version:7.123 } 

Then what should qname be? auth:AuthenticationHeader? Where do I specify the namespace?

Is there an easier example with node-soap? Should I use strong-soap or node-soap?

2 Answers 2

9

I found the way to do that by reading through the codebase. (strong-soap)

qname - qualified name

for simple headers

const QName = require('strong-soap').QName; client.addSoapHeader({ item: { key: 'api_key', value: apiKey } }, new QName(nsURI, 'Auth')); 

for complex headers like you have, specify it in xml directly

client.addSoapHeader( `<aut:Auth xmlns:aut="${nsURI}"> <aut:LoginName>foo</aut:LoginName> </aut:Auth>` ); 
Sign up to request clarification or add additional context in comments.

Comments

0

Just in case somebody else comes here looking for answers:

const QName = require('strong-soap').QName; client.addSoapHeader( { $value: { LoginName: 'foo', Password: 'secret', Culture: 'en_US', Version: '7.123', }, }, new QName( 'http://schemas.foo.com/webservices/authentication', 'AuthenticationHeader', ) ); 

1 Comment

Hi! Please elaborate your code

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.