1

I haven't used soap until now. I'm using node-soap library (https://github.com/vpulim/node-soap).

I want to communicate with soap server. To maintain the session the server sends me set-cookie response header: 'ASP.NET_SessionID=55....hrc; path/; HttpOnly' with the Login method response. I want to send this cookie back in a Logout method request.

I try: client.addHttpHeader('Cookie', 'ASP.NET_SessionID=55....hrc');

But on subsequent:

client.LogoutAsync({})
    .then(result => {console.log(result);})
    .catch(error => {console.log(error);});

I get an error:

events.js:183 throw er; //Unhandled 'error' event

What's going on here, and how can I send back Cookie header?

P.S. Wihtout cookie it works as expected returning me Logout: false, meaning the error occured because it didn't recognized session (I suppose).

croraf
  • 4,332
  • 2
  • 31
  • 50

2 Answers2

2

I had the same issue and found it can be done with headers:

soap.createClientAsync(this.url, this.options).then(client => {
  client.addHttpHeader('Cookie', 'ASP.NET_SessionId=' + this.sessionId)
  client.GetIdentity((err, results) => {
    if (err) reject(err)
    resolve(results)
  })
})
Steffan
  • 704
  • 1
  • 11
  • 25
0

We just faced the same issue and found an easy solution.

The request library which is being used by the soap library supports a concept of cookie jars.

You can enable it by adding the jar option to all the requests. For example:

client.LoginAsync({}, { jar: true });
client.LogoutAsync({}, { jar: true });

This stores the cookies globally.

If you want to store the cookies locally (e.g., per session), you can use a custom cookie jar object, that will be used only for a specific scope, like:

const request = require('request');

const myJar = request.jar();
client.LoginAsync({}, { jar: myJar });
client.LogoutAsync({}, { jar: myJar });
yoshigev
  • 13
  • 3