Copy link to clipboard
Copied
We are calling IDS from a nodejs app using the "node-soap" component. We are now introducing sessions and encountering the issue.
I just stared a session and tried to close it. Always get error message inside the event soapError saying "Client opened session with ID 1 but the SOAP header targets session with ID 2!" .If I try to run it again I get error "Client opened session with ID 1 but the SOAP header targets session with ID 3!". Tried runscript() also , It ran successfully but still get the error message.
I use indesign server 2015.
Please see the code which I use,
var soap = require("soap");
var url = "http://localhost:8194/wsdl?wsdl";
var args = { "IDSP:runScriptParameters":
{
"scriptLanguage": "javascript",
"scriptFile": scriptPath,
"IDSP:scriptArgs" : [
{ "IDSP:name" : "user",
"IDSP:value" : thisUser}
]
}
};
soap.createClient(url, function(err, client) {
client.on("soapError", function(err) {
console.log(err.message);
return errDataCallback(soapErr);
});
var sessionId;
client.BeginSession(function(err,session,test1){
sessionId = session.sessionID;
console.log("sessionID : "+sessionId);
if(err){
return errDataCallback(err);
}
var result = client.addSoapHeader({"sessionID":sessionId},"sessionID","IDSP","");
var sessionArg = { "IDSP:sessionID": sessionId.toString()};
client.EndSession(sessionArg, function(err){
console.log(err.message);
});
});
});
Please help me to resolve the issue.
Ok I finally figure it out.
The issue is that IDS attach in some way a socket to a session.
So whenever the socket is closed, the session is closed as well.
The trick in nodejs is to create a custom http.Agent you pass to your http request for each session you want to be maintained with (for example) those params :
let keepAliveAgent = new http.Agent({
keepAlive: true, // so the socket is not closed after http request completion (do not forget to do a request.end() after your request.wri
...
Copy link to clipboard
Copied
Moving to InDesign Server Developers Forum
Copy link to clipboard
Copied
Anybody worked with Indesign server + node js.
Is there anyone form Adobe team to help with ?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Ok I finally figure it out.
The issue is that IDS attach in some way a socket to a session.
So whenever the socket is closed, the session is closed as well.
The trick in nodejs is to create a custom http.Agent you pass to your http request for each session you want to be maintained with (for example) those params :
let keepAliveAgent = new http.Agent({
keepAlive: true, // so the socket is not closed after http request completion (do not forget to do a request.end() after your request.write())
keepAliveMsecs:600000, // set to enough time to not have the connection timed out
maxSockets:1 // ensure that the Agent does not open an other parralell socket
});
Then for each http request you create to be executed within the session (including the beginSession and endSession) you pass that Agent as parameter :
RequestOptions = {
hostname: server.hostname,
port: server.port,
path: server.path,
method: 'POST',
headers: {
'Content-Type': 'text/xml;charset=UTF-8',
'Content-Length': Buffer.byteLength(postData),
'Connection': 'Keep-Alive',
'SOAPAction':'""'
},
agent:keepAliveAgent
}
For any new session, you just create a new http.Agent ...