lula / ngx-soap

Simple SOAP client for Angular
MIT License
66 stars 60 forks source link

Importing Ngx-Soap in angular 2 #10

Closed yuvanesh10 closed 6 years ago

yuvanesh10 commented 6 years ago

I am trying to implement ngx-soap package in my Angular 4 application. I am using Node server and tried to create soap client and server file using this package strong-soap successfully implemented with the help I have got from here. Now I would to make the client in frontend.

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

    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 in this part", 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 ?

ERRORS

lula commented 6 years ago

Errors are related to the fact that you're missing the property declarations in your AppComponent class. E.g

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
  jsonResponse: any;
  xmlResponse: string;
  loading: boolean;  // fixes error TS2339: Property 'loading' does not exist on type 'AppComponent'.
...

I don't understand what you're trying to achieve. ngx-soap should be used in the client only, when you don't have any backend. If you have a backend you can work with, I would say it's better to rely on it, and have the backend do you soap calls. You just need to wrap it in some REST Api for instance.

yuvanesh10 commented 6 years ago

I solved those errors . but I would like to use ngx-soap in angular to make a wsdl call

yuvanesh10 commented 6 years ago

I have solved most of them. Can you tell me what am I doing wrong here ? error2

@lula