正文错误:在Angular 4中实现ngx-soap客户端 [英] Body error: Implementing ngx-soap client in Angular 4

查看:144
本文介绍了正文错误:在Angular 4中实现ngx-soap客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Angular 4应用程序中尝试在

解决方案

首先为了解决..,我重新编辑了在问题中更新的代码.然后有跨域错误.这可以通过在代码中添加插件或标头来解决.

然后我使用了下面的功能.

  function dbQuery(){var response = db.query(aqlQuery`LET startVertex =(FOR DOC IN规范FILTER doc.serial_no =='"123456abcde"'极限2退货文件)[0]FOR v IN 1任意startVertex当属返回v.ip`,{bindVar1:'值',bindVar2:'值',});console.log("response is" + response);返回响应;}//在另一个异步函数中使用函数main2(){var result2 = dbQuery();返回result2.then(function(test){console.log("test is" + JSON.stringify(test._result));var IP = test._result.filter(Boolean);console.log("Ip是" + IP);});}main2();  

I am trying to implement ngx-soap package here in my Angular 4 application. I am using Node server and tried to create soap client and server file using this package here and successfully implemented with the help I have got from here. Now I would to make the client in frontend. I have defined the body and but not sure whether that is correct.

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));
  }

}

In Node, I have serverfile where I am trying to access the query from arangodb and once I run my client file .,I am able to print out the result envelope in console.I would like to do the same but from 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);

Since I am new to working with backend services. I couldn't solve the basic errors. I am not getting the proper hang of it.Like how to approach it ?

ERROR

解决方案

First In order to solve..,I have re-edited the code which I have updated in the question. Then there was errors for cross-origin. That can be solved either by adding plugins or headers to the code.

Then I have used the function below.

function dbQuery() {
          var response = 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',
                });
console.log("response is "+ response);
    return response;
}

//usage inside another async function

function main2() {
        var result2 = dbQuery();

        return result2.then(function(test){

                console.log("test is "+JSON.stringify(test._result));
                var IP = test._result.filter(Boolean);
                console.log("Ip is "+IP);
});
}
main2();

这篇关于正文错误:在Angular 4中实现ngx-soap客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆