lehh / nestjs-soap

Nestjs module wrapper for soap npm package
MIT License
21 stars 14 forks source link

Cannot import SoapModule correctly #27

Open cagrisungur opened 2 years ago

cagrisungur commented 2 years ago

Hi there.

Here is my module.

@Module({ imports: [ SoapModule.registerAsync({ clientName: 'MY_SOAP_CLIENT', imports: [ConfigModule], inject: [ConfigService], useFactory: async ( configService: ConfigService, ): Promise<SoapModuleOptions> => ({ uri: configService.get<string>('SOAP_URL'), clientName: 'MY_SOAP_CLIENT', auth: { type: 'basic', username: configService.get<string>('SOAP_USERNAME'), password: configService.get<string>('SOAP_PASSWORD'), }, }), }), ], controllers: [LmsManagementController], providers: [LmsManagementService], })

And my service constructor and function.

@Inject('MY_SOAP_CLIENT') private readonly mySoapClient: Client console.log(await this.mySoapClient.GetKey());

Client always says null, not able to console any other function in it.

What is the problem exactly?

lehh commented 2 years ago

Hello @cagrisungur,

Apparently everything is right, the soap client shouldn't be null. Which version are you using?

The only thing that is missing there is the Async word in this.mySoapClient.GetKey(). Could you try again calling your function like this: this.mySoapClient.GetKeyAsync().

duhovich commented 2 years ago

Same error +1

cagrisungur commented 2 years ago

Same error +1

I've fixed this problem. Forked the library changed little bit.

I can share you later when i customized it. Without customized, i couldn't managed to run. @lehh

lehh commented 2 years ago

Yes, please, share it so I can fix it on the package if that's the case.

duhovich commented 2 years ago

In my case, the problem was with the WSDL url. The error was not thrown and just returned null

CretanBull commented 2 weeks ago
Node version: v20.13.1
Nestjs-soap version: ^3.0.2

I'm facing a dependency injection issue even after following the documentation. It would be good if anyone can tell what I'm doing wrong. My goal is to import a single client at the app.module level and then just use that client in all other modules. My import code looks as follows:

// app.module.ts

@Module({
  imports: [
    // ...
    MoviesModule,
    SoapModule.forRootAsync({
      clientName: 'MY_SOAP_CLIENT',
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (_configService: ConfigService): Promise<SoapModuleOptions> => ({
        clientName: 'MY_SOAP_CLIENT',
        uri: 'https://www.dataaccess.com/webservicesserver/NumberConversion.wso?wsdl',
      }),
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

and then I tried to import it in my movies.module as follows:

// movies.module.ts

@Module({
  imports: [TypeOrmModule.forFeature([Movie]), SoapModule],
  controllers: [MoviesController],
  providers: [MoviesService],
})
export class MoviesModule {}
// movies.service.ts

@Injectable()
export class MoviesService {
  constructor(
    @InjectRepository(Movie) private readonly moviesRepository: MoviesRepository,
    @Inject('MY_SOAP_CLIENT') private readonly soapClient: Client,
  ) {}

  // ...

  async getNumberInWords(ubiNum: number): Promise<string> {
    const resp = await this.soapClient.NumberToWordsAsync({ ubiNum });
    console.log(resp);
    return null;
  }
}

But still I get the following error:

[Nest] 59820  - 29/08/2024, 7:11:46 am   ERROR [ExceptionHandler] Nest can't resolve dependencies of the SoapService (?). Please make sure that the argument "SOAP_MODULE_OPTIONS" at index [0] is available in the SoapModule context.

Potential solutions:
- Is SoapModule a valid NestJS module?
- If "SOAP_MODULE_OPTIONS" is a provider, is it part of the current SoapModule?
- If "SOAP_MODULE_OPTIONS" is exported from a separate @Module, is that module imported within SoapModule?
  @Module({
    imports: [ /* the Module containing "SOAP_MODULE_OPTIONS" */ ]
  })