Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set headers using node-soap in node.js

I am trying to consume a wsdl service and found node-soap, but I cannot find how to set some headers.

Example :

header = {
  "Username": "foo",
  "Password" : "bar"
}

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

Thanks in advance

like image 423
Vartan Arabyan Avatar asked May 18 '12 21:05

Vartan Arabyan


People also ask

How do I add a header in node JS?

We will use request. setHeader() to set header of our request. The header tells the server details about the request such as what type of data the client, user, or request wants in the response. Type can be html , text , JSON , cookies or others.

What is header in SOAP request?

The SOAP header is an optional section in the SOAP envelope, although some WSDL files require that a SOAP header is passed with each request. A SOAP header contains application-specific context information (for example, security or encryption information) that is associated with the SOAP request or response message.


1 Answers

It may not be useful now however inorder to answering this question which is still open, here it goes.

You can make use of the method Client.addSoapHeader. As per the documentation

Client.addSoapHeader(soapHeader[, name, namespace, xmlns]) - add soapHeader to soap:Header node

Options

soapHeader Object({rootName: {name: "value"}}) or strict xml-string Optional parameters when first arg is object :

name Unknown parameter (it could just a empty string)

namespace prefix of xml namespace

xmlns URI

So you need to create an object and pass that to this method like:

var soapHeader = {
  "Username": "foo",
  "Password" : "bar"
};
client.addSoapHeader(soapHeader);
like image 172
V31 Avatar answered Sep 21 '22 09:09

V31