How to consume SOAP services in NestJS with nested arguments?

34 Views Asked by At

I'm requesting a soap api with the npm package 'nestjs-soap'

My request body in XML looks something like this

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<search xmlns="some url">
<bList>
<identnr>1</identnr>
<name>some name</name>
<typ>some type</typ>
</bList>
</search>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I am using the soap module from nestjs-soap like this

@Module({})
export class SomeModule {
  static forRoot(): DynamicModule {
    return {
      module: SomeModule,
      imports: [
        HttpModule,
        SoapModule.register({
          clientName: 'SomeSoapClient',
          uri: './wsdl/some_wsdl.wsdl',
        }),
      ],
      providers: [SomeSoapService],
      controllers: [SomeSoapController],
      exports: [SomeSoapService],
    };
  }
}

Now in my SomeSoapService I am calling my soap api.

try {
      response = await this.someSoapClient.search({
        blist: {
          identnr: 'some number',
          name: 'some name',
          typ: 'some type',
        },
      });
    } catch (error) {
      this.logger.error((error as Error).message ?? error);
      throw new BadGatewayException('Invalid Response from SomeSoap');
    }

I do not get an error but an undefined response. When calling the service via postman and with the XML as request body I get the desired response.

My question: How do I need to pass the arguments in the search method correctly to account for the nested structured in the body of the xml?

0

There are 0 best solutions below