Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to call SOAP web services #2284

Closed
Onkarn92 opened this issue Jun 10, 2016 · 3 comments
Closed

[Question] How to call SOAP web services #2284

Onkarn92 opened this issue Jun 10, 2016 · 3 comments
Assignees
Labels

Comments

@Onkarn92
Copy link

tns version - 2.0.1
Platform - android

Hi, I want to use SOAP web services with SOAP request & response format in nativescript. In android there is soap library "ksoap2-android", but i didn't find any soap library in nativescript. I need to pass data in XML format. is there any plugin/library in nativescript for SOAP services?. I tried following code but didn't worked for me -

 var xmlHttp = new XMLHttpRequest();
    xmlHttp.open('POST','http://MY_DOMAIN_ADDRESS/WebService.asmx',true);
    var soapRequest =  '<?xml version="1.0" encoding="utf-8"?>' +
                        '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"'+
                        '<soapenv:Header/>'+
                        '<soapenv:Body>'+
                            '<web:GetUserLoginForApp>'+                          
                                '<web:UserName>USERNAME</web:UserName>'+                         
                                '<web:Password>PASSWORD</web:Password>'+
                            '</web:GetUserLoginForApp>'+
                        '</soapenv:Body>'+
                        '</soapenv:Envelope>' ;

                         xmlHttp.onreadystatechange = function () {
                            if (xmlHttp.readyState == 4) {
                                if (xmlHttp.status == 200) {
                                    alert('done. use firebug/console to see network response');
                                }
                            }
                        }
       xmlHttp.setRequestHeader('Content-Type', 'text/xml');
            xmlHttp.send(soapRequest);

I did console.log, but output is null/UNKNOWN. I'm confused about the problem. Please help me :) Thanks

@NickIliev NickIliev self-assigned this Jun 14, 2016
@NickIliev
Copy link
Contributor

NickIliev commented Jun 14, 2016

Hello @Onkarn92

Do you have actual SOAP service from which you can receive a response!?
For example I have used this test service from w3schools

http://www.w3schools.com/webservices/tempconvert.asmx

And was able to receive a response with no problem.
For example in your code use this line:

xmlHttp.open('POST','http://www.w3schools.com/webservices/tempconvert.asmx',true);

and also log the response from the service

        if (xmlHttp.readyState == 4) {
            console.log(xmlHttp.responseText);
            // ... more code follows

Of course you will have to modify your soapRequest to actually convert from Fahrenheit (in your case you will have to pass your login service) but still you will receive a response with html page 404 which is valid response

@therevills
Copy link

Hi, I've managed to call my WS but I dont know how to parse the reponseText. Could you please show me an example on parsing? I've found that NS has an XML Parser (https://docs.nativescript.org/cookbook/xml-parser#xml-module) but having trouble using it with TypeScript...

@lock
Copy link

lock bot commented Sep 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Sep 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants