2017-09-19 14 views
4

まだ私はangular2を学んでいます。 SOAPリクエストをWSDLを使ってWebサービスに送信する方法を学びたいと考えています。私はいくつかの例を探していて、見つけました。私はボタンを作成し、そのソープ関数をクリックしてサーバーにリクエストを送るように呼びたいと思っていました。プロジェクトは正常に構築されていますが、機能は動作しません。SOAP - WSDLリクエストangular2/4フレームワーク

app.component.ts 

    import { Component } from '@angular/core'; 
    import { Http, Response, RequestOptions, Headers} from '@angular/http'; 
    import 'rxjs/add/operator/map'; 
    declare var angular: any; 

    @Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html' 
    }) 

export class AppComponent { 

soapCall() { 

    angular.module('myApp', ['angularSoap']); 
     var xmlhttp = new XMLHttpRequest(); 
    // xmlhttp.open('POST', 'http://localhost/webservices/voltage-info-service/wsdl/sgcc3.wsdl', true); 
     xmlhttp.open('POST', 'http://localhost/webservices/voltage-info-service/server/server.php', true); 
     //var input_element = <HTMLInputElement> document.getElementById("choosenNumber"); 
     //console.log("chVal : " + this.chVal); 
     //this.choosenNumberValue = this.chVal; 

    //the following variable contains my xml soap request (that you can get thanks to SoapUI for example) 

      var sr = 'YEAH'; 
      // '<?xml version="1.0" encoding="utf-8"?><lfc:requests><lfc:request><lfc:busID>66</lfc:busID><lfc:timestamp>223456789</lfc:timestamp><lfc:coordinates>'+ 
      // '<lfc:LongD>8</lfc:LongD><lfc:LongM>6</lfc:LongM><lfc:LongS>25.599</lfc:LongS><lfc:LatD>51</lfc:LatD><lfc:LatM>33</lfc:LatM><lfc:LatS>23.9898</lfc:LatS>'+ 
      // '</lfc:coordinates></lfc:request></lfc:requests>'; 

     xmlhttp.onreadystatechange =() => { 
      if (xmlhttp.readyState == 4) { 
       if (xmlhttp.status == 200) { 
        var xml = xmlhttp.responseXML; 
        // this.response_number = parseInt(xml.getElementsByTagName("return")[0].childNodes[0].nodeValue); //Here I'm getting the value contained by the <return> node 
        console.log('Work!!');                 //I'm printing my result square number 
       } 
      } 
     } 

     // Send the POST request 

     xmlhttp.setRequestHeader('Content-Type', 'text/xml'); 
     xmlhttp.responseType = "document"; 
     xmlhttp.send(sr); 
    } 
    } 

app.component.html 

<u1> 
<u1> 
    <input type="button" value="SOAP request" ng-click="soapCall()"> 
</li> 
</ul> 
+1

https://scotch.io/tutorials/angular-2-http-requests-with-observables –

+0

@SachilaRanawaka以下のようにSOAPメソッドのコードを変更し、私はあなたが与えたチュートリアルを理解couldntの.. 、私のレベルから遠くへの道 –

答えて

4

エラーにはSOAP関連のエラーは表示されません。すべてのエラーは、プロパティがAppComponentに存在しないことを示します。

soapCall() { 
    let xmlhttp = new XMLHttpRequest(); 
    xmlhttp.open('POST', 'http://localhost/webservices/voltage-info-services/wsdl/sgcc3.wsdl', true); 
    let input_element = <HTMLInputElement> document.getElementById("choosenNumber"); 

    console.log("chVal : " + input_element.value); 
    let choosenNumberValue = input_element.value; 
    //the following variable contains my xml soap request (that you can get thanks to SoapUI for example) 
    let sr = 
     `<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mat="http://mathsutility.test.com/"> 
     <soapenv:Header/> 
     <soapenv:Body> 
     <mat:carreNombre> 
      <arg0>` + choosenNumberValue + `</arg0> 
     </mat:carreNombre> 
     </soapenv:Body> 
    </soapenv:Envelope>`; 

    xmlhttp.onreadystatechange = () => { 
     if (xmlhttp.readyState == 4) { 
      if (xmlhttp.status == 200) { 
       let xml = xmlhttp.responseXML; 
       let response_number = parseInt(xml.getElementsByTagName("return")[0].childNodes[0].nodeValue); //Here I'm getting the value contained by the <return> node 
       console.log(response_number); //I'm printing my result square number 
      } 
     } 
    } 
    // Send the POST request 
    xmlhttp.setRequestHeader('Content-Type', 'text/xml'); 
    xmlhttp.responseType = "document"; 
    xmlhttp.send(sr); 
    } 
+0

私はほとんどのエラーをslovedして..、私は "参照エラー:角度未定"を取得しています.. !! soapCall関数を正しくインポートしましたか? –

+0

エラースタックトレースを提供できますか? –

+0

index.html https://github.com/andrewmcgivery/angular-soap 私はこの時点でエラーが発生しています –