Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

349
Vistas
Soap call with NestJS

I have to call SOAP webservice and serve it. I am using strong-soap library(https://github.com/loopbackio/strong-soap). I get my data in the service and I can see it in console.log() but I can't send this data to my controller to serve it. I have tried using pipe(map()) and I have looked into this following topics (https://www.freecodecamp.org/news/an-express-service-for-parallel-soap-invocation-in-under-25-lines-of-code-b7eac725702e/) but no luck. I either get 'can't subscribe to undefined' or my request is passing without my controller getting the data and serving it.

Here is my controller.ts

 export class MyController {

    constructor(private readonly service: Service){}

    @Get('/example')
    getAll(@Query() query: Query){
        return this.service.getAll(query);
    }

}

and here is my service

    export class Service {

    private URL = process.env.URL;
    constructor() { }

    async getAll(query: OrderRequest) {
        const request = {
            req: {
               req: query,
            }
        };

        return await soap.createClient(this.URL, (err, client) => {
            if (err) {
                console.error(err);
            } else {
                let method = client.myMethodName;
                method(request, (err, result, envelope, soapHeader) => {
                    
            // here I am getting the data but 'return result. is not sending it to the controller        

console.log(result[0])
return result
                });
            }
        });
    }
}

As I said I have tried with map and pipe like this:

 return await soap.createClient(this.URL).pipe(map((err, client) => {
            if (err) {
                console.error(err);
            } else {
                let method = client.myMethodName; // here I have an error
                method(request, (err, result, envelope, soapHeader) => {
                    console.log(result)
                });
            }
        })) 

but I can't pass my method in the client. Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

OK I have found the solution. Thing is the function above was returning the promise so solution was to initialize new promise and handle reject and resolve. Like this we get the results in resolve and take them with .then() in our controller.

Here is the code:

service.ts

getAll(query: Query) {
        const request = {query: {query: query}};
        return new Promise ((resolve, reject) => { // here we add new Promise
            soap.createClient(this.URL, (err, client) => {
                if (err) {
                    return reject(err); // if error reject promise
                } else {
                    return resolve(client); // else resolve and send client
                    });
                }
            });
        }   
    )}

controller.ts

getAll(@Query() query: query){
    console.log(this.service.getAll(query))
    return this.service.getAll(query).then(result=>result)
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda