gpt4 book ai didi

angular - SOAP - WSDL 请求 angular2/4 框架

转载 作者:太空狗 更新时间:2023-10-29 17:18:54 34 4
gpt4 key购买 nike

我还在学习angular2。我正在尝试学习如何使用 WSDL 将 SOAP 请求发送到 Web 服务。我正在寻找一些例子并找到了一个。我创建了一个按钮并希望调用该 soap 函数以通过单击将请求发送到服务器。项目构建成功但功能不可用。

 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/server/server.php', true);

//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;
//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>

最佳答案

错误不显示任何与 SOAP 相关的错误。所有错误都表明该属性在 AppComponent 中不存在。

修改soap方法代码如下

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

console.log('chVal : ' + input_element.value);
const choosenNumberValue = input_element.value;

// The following variable contains the xml SOAP request.
const 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) {
const xml = xmlhttp.responseXML;
// Here I'm getting the value contained by the <return> node.
const response_number = parseInt(xml.getElementsByTagName('return')[0].childNodes[0].nodeValue);
// Print result square number.
console.log(response_number);
}
}
}
// Send the POST request.
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.responseType = 'document';
xmlhttp.send(sr);
}

关于angular - SOAP - WSDL 请求 angular2/4 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46296983/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com