问题描述
我正在寻找一种使用WSDL将SOAP请求发送到Web服务的方法。使用Typescript 2和Angular 2可以做到这一点吗?
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 ?
我见过Angular 1的教程,但他们使用旧的角度方法,比如 factory
或 controller
。
I've seen tutorials for Angular 1 but they used old angular methodes, like factory
or controller
.
我想如果可能的话,用TypeScript做一个新方法。
I would like if it's possible, a new way to do that with TypeScript.
任何想法?
推荐答案
你需要的是一个包裹 Http
的服务并提供反序列化:
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(...);
}
}
由于我不是xml解析专家,我不能告诉你如何des您可以查看您的XML,但是您可以查看只需将序列化/反序列化过程包装在另一个服务中并将其注入 SOAPService
。
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
.
这篇关于使用angular 2创建SOAP客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!