Skip to Content
0

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

May 02 at 01:50 PM

62

avatar image

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);

});

}

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Ralph Oliveira
May 15 at 11:28 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded