Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

348
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!