1.安装插件
npm install --save ngx-soap
npm install --save buffer concat-stream core-js crypto-js events lodash sax stream uuid
2.添加模块
将NgxSoapModule添加到您的应用模块
import { NgxSoapModule } from 'ngx-soap';
...
@NgModule({
imports: [ ..., NgxSoapModule, ... ]
...
3.使用
...
import { NgxSoapService, Client, ISoapMethodResponse } from 'ngx-soap';
...
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
xmlResponse:any;
client: Client;
intA = '参数1';
intB = '参数2';
url = 'WebService.asmx?WSDL';
constructor(private soap: NgxSoapService) {
this.soap.createClient(this.url).then(client => {
console.log('Client', client);
this.client = client;
})
.catch(err => console.log('Error', err));
}
sum() {
const body = {
intA: this.intA,
intB: this.intB
};
this.client.call('Add', body).subscribe(res => {
this.xmlResponse = res.responseBody;
}, err => console.log(err));
}
}
网友评论