【发布时间】:2018-02-13 14:05:33
【问题描述】:
我正在尝试在我的 Angular 4 应用程序中实现 ngx-soap 包 here。我正在使用 Node 服务器并尝试使用此包 here 创建soap客户端和服务器文件,并在我从这里获得的帮助下成功实现。现在我要在前端制作客户端。我已经定义了body,但不确定是否正确。
import {Component, OnInit} from '@angular/core';
import {SOAPService, Client} from 'ngx-soap';
import {Http} from '@angular/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
jsonResponse: any;
xmlResponse: string;
loading: boolean;
message: string;
private client: Client;
constructor(private http: Http, private soap: SOAPService) {}
ngOnInit() {
this.http.get('/assets/check_username.wsdl').subscribe(response => {
if (response && response.text()) {
this.soap.createClient(response.text()).then((client: Client) => {
this.client = client;
});
}
});
}
client_wsdl() {
this.clear();
this.loading = true;
let body = {
userName:"TEST_USER"
};
this.client.operation('checkUserName', body)
.then(operation => {
if (operation.error) {
console.log('Operation error', operation.error);
return;
}
let url = operation.url.replace("http://www.examples.com/", "/CheckUserName");
this.http.post(url, operation.xml, {
headers: operation.headers
}).subscribe(
response => {
this.xmlResponse = response.text();
this.jsonResponse = this.client.parseResponseBody(response.text());
try {
this.message = this.jsonResponse.Body.CheckUserNameResponse;
} catch (error) {}
this.loading = false;
},
err => {
console.log("Error calling ws", err);
this.loading = false;
}
);
})
.catch(err => console.log('Error', err));
}
}
在节点中,我有服务器文件,我试图从 arangodb 访问查询,一旦我运行我的客户端文件,我就可以在控制台中打印出结果信封。我想做同样的事情,但来自 Angular 4.
server.js
var soap = require('strong-soap').soap;
var http = require('http');
var myService = {
CheckUserName_Service: {
CheckUserName_Port: {
checkUserName: function(args, soapCallback) {
console.log('checkUserName: Entering function..');
db.query(aqlQuery `
LET startVertex = (FOR doc IN spec
FILTER doc.serial_no == '"123456abcde"'
LIMIT 2
RETURN doc
)[0]
FOR v IN 1 ANY startVertex belongs_to
RETURN v.ip`, {
bindVar1: 'value',
bindVar2: 'value',
}).then(function(response) {
console.log(`Retrieved documents.`, response._result);
soapCallback(JSON.stringify(response._result));
})
.catch(function(error) {
console.error('Error getting document', error);
soapCallback('Error getting document' + error.message);
});
}
}
}
};
var xml = require('fs').readFileSync('check_username.wsdl', 'utf8');
var server = http.createServer(function(request, response) {
response.end("404: Not Found: " + request.url);
});
var port = 8000;
server.listen(port);
var soapServer = soap.listen(server, '/test', myService, xml);
soapServer.log = function(type, data) {
console.log('Type: ' + type + ' data: ' + data);
};
console.log('SOAP service listening on port ' + port);
因为我是使用后端服务的新手。我无法解决基本错误。我没有掌握正确的窍门。比如如何处理它?
错误
【问题讨论】:
-
查看您对
this的所有使用情况。this(即 AppComponent)上是否存在这些属性? -
@PaulSamsotha 是的,这是一个错误..,我没有正确导入包。,我现在会更正
标签: node.js angular web-services soap wsdl