typescript 使用 angular 2 创建 SOAP 客户端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39890719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:54:35  来源:igfitidea点击:

Creating a SOAP client with angular 2

soapangulartypescriptionic-frameworksoap-client

提问by Couim

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 ?

我正在寻找一种使用 WSDL 将 SOAP 请求发送到 Web 服务的方法。是否可以使用 Typescript 2 和 Angular 2 做到这一点?

I've seen tutorials for Angular 1 but they used old angular methodes, like factoryor controller.

我看过 Angular 1 的教程,但他们使用了旧的角度方法,例如factorycontroller

I would like if it's possible, a new way to do that with TypeScript.

如果可能的话,我想要一种使用 TypeScript 做到这一点的新方法。

Any ideas ?

有任何想法吗 ?

回答by Supamiu

What you need is a service that wraps around Httpand provides deserialization:

您需要的是一个环绕Http并提供反序列化的服务:

@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 MDNfor that, you simply have to wrap the serialization/deserialization process in another service and inject it in your SOAPService.

由于我不是 xml 解析专家,我不能告诉您如何反序列化您的 XML,但是您可以检查MDN,您只需要将序列化/反序列化过程包装在另一个服务中并将其注入您的SOAPService.

回答by John

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:

您可以将常规 http 请求与 Angular2 的 [ Http class] ( https://angular.io/docs/ts/latest/api/http/index/Http-class.html) 一起使用,这是他们页面上的一个示例:

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.

您可以使用 URL 代替请求 json 文件。