I have to consume a SOAP service in NestJs for one of my projects. I am trying to consume a dummy SOAP service from web. Below are the details -
URL -
http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL
Method - POST
Headers -
Content-Type: text/xml
Request Body -
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<CapitalCity xmlns="http://www.oorsprong.org/websamples.countryinfo">
<sCountryISOCode>IN</sCountryISOCode>
</CapitalCity>
</Body>
</Envelope>
Response Body -
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<m:CapitalCityResponse xmlns:m="http://www.oorsprong.org/websamples.countryinfo">
<m:CapitalCityResult>New Delhi</m:CapitalCityResult>
</m:CapitalCityResponse>
</soap:Body>
</soap:Envelope>
Now I am not able to figure out how to consume this service in my NestJs dummy application. By exploring for quite sometime, I found a library nestjs-soap, which I installed and configured as mentioned below -
npm install nestjs-soap --save
My app.module.ts -
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SoapModule } from 'nestjs-soap';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true
}),
SoapModule.registerAsync([
{ name: 'MY_DUMMY_CLIENT', uri: `http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL` }
])
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
My app.service.ts -
import { Inject, Injectable } from '@nestjs/common';
import { Client } from 'nestjs-soap';
@Injectable()
export class AppService {
constructor(@Inject('MY_DUMMY_CLIENT') private readonly myDummyClient: Client) {}
getHello(): string {
return process.env.APP_MESSAGE;
}
getDetails(): string {
return process.env.APP_DETAILS;
}
asyncGetCountryCapital() {
//this.myDummyClient.
}
}
As the documentation I referred is not in detail, I am not able to figure out how to call the SOAP service within asyncGetCountryCapital() function.