I'm looking for a way to send SOAP request to a web service, with a WSDL. Is it possible to do that with Typescript 2 and Angular 2 ?
I've seen tutorials for Angular 1 but they used old angular methodes, like factory
or controller
.
I would like if it's possible, a new way to do that with TypeScript.
Any ideas ?
What you need is a service that wraps around Http
and provides deserialization:
@Injectable()
export class SOAPService{
constructor(private http:Http){}
public get(url:string, options?:RequestOptionsArgs):Observable<any>{
return this.http.get(url, options).map(res => {
let xmlresult = res.text();
let result = //Here you deserialize your xml object
return result;
}
}
}
Then you can use it this way:
@Component({...})
export class ExampleComponent{
constructor(private soap:SOAPService){}
foo():{
this.soap.get('foo/bar').subscribe(...);
}
}
Since I'm not an xml parsing expert, I can't tell you how to deserialize your XML, but you can check MDN for that, you simply have to wrap the serialization/deserialization process in another service and inject it in your SOAPService
.
You could use a regular http-request with Angular2's [Http class
] (https://angular.io/docs/ts/latest/api/http/index/Http-class.html)
This is an example from their page:
import {Http, HTTP_PROVIDERS} from '@angular/http';
import 'rxjs/add/operator/map'
@Component({
selector: 'http-app',
viewProviders: [HTTP_PROVIDERS],
templateUrl: 'people.html'
})
class PeopleComponent {
constructor(http: Http) {
http.get('people.json')
// Call map on the response observable to get the parsed people object
.map(res => res.json())
// Subscribe to the observable to get the parsed people object and attach it to the
// component
.subscribe(people => this.people = people);
}
}
instead of asking for a json file, you could use a URL instead.