cancel
Showing results for 
Search instead for 
Did you mean: 

Problemas al conectar Service Layer en JavaScript / Problems to connect Service Layer in JavaScript

vanesa_moreno
Discoverer
0 Kudos

Estoy realizando un conector a ServiceLayer en JavaScript con Node.js y Express. Cuando intenta hacer la conexión se queda un rato esperando respuesta y da el error “SOCKET HANG UP”. Si realizo la misma conexión a través del POSTMAN me funciona correctamente.

He comprobado la configuración del Service Layer según se indicaba en otros blogs. También he buscado por foros y tras probar las distintas soluciones me sigue dando el mismo error.

Adjunto como realizo la conexión:

I’m developing a connector to ServiceLayer in JavaScript with Node.js and Express. When it tries to make the connection it waits for a while waiting for an answer and it gives the error “SOCKET HANG UP”. If I make the same connection through POSTMAN, it works correctly.

I have checked the configuration of the Service Layer as indicated in other blogs. I have also searched through forums and after trying the different solutions I still get the same error.

I attach how I made the connection:

var https = require(‘https‘);

var connected = false;

var SessionID;

var SLServer;

exports.connectSL = function(re, res){

if(connected){

return;

}

var post_req = null,

post_data = re;

var post_options = {

hostname: ‘172.25.133.232’,

port : ‘50000’,

path : ‘b1s/v1/Login’,

method : ‘POST’,

body : post_data,

json : true,

headers : {

‘Content-Type’: ‘application/json‘,

‘Cache-Control’: ‘no-cache’,

‘Content-Length’: post_data.length

},

rejectUnauthorized: false,

requestCert: true,

agent: false

};

console.log(‘Realizando conexion‘);

process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

post_req = https.request(post_options, function (res) {

console.log(‘STATUS: ‘ + res.statusCode);

console.log(‘HEADERS: ‘ + JSON.stringify(res.headers));

res.setEncoding(‘utf8’);

res.on(‘data’, function (chunk) {

console.log(‘Response: ‘, chunk);

});

});

post_req.on(‘error’, function(e) {

console.log(‘problem with request: ‘ + e.message);

});

}

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member197733
Contributor
0 Kudos

I have done a couple of examples with Node and SL.

Please check:

here is a tutorial repo: https://github.com/B1SA/cfDemoSummit18.

Here is another quick sample creating activities and messages: https://github.com/Ralphive/b1leo/blob/master/modules/serviceLayer.js

And the latest one using Redis to save the sl session in cache (I will write a blog about it) - https://github.com/B1SA/smbmkt/blob/master/modules/erp/b1.js