Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How to post soap request and parse xml result form a web service

I have to develop an application program for android with Titanium Studio 1.7.2.
To do this, I have to call a web service and parse the response. I tried this :

var url="https://minos.altran.com/minosweb/mnbzt_soap.php?action=MOBCONGEST_query";
    var xhr = Titanium.Network.createHTTPClient();

    var soapRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
    "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + 
    "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
    "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
    "<soap:Header/>" +    
    "<soap:Body>" +
    "<body xsi:type=\"data:query_params\" xmlns:data=\"http://minos.altran.com/MOBCONGEST/Data/\">" +
                "<query_type>get_user_profil</query_type>" +
                   "<user xsi:type=\"data:user_profil\">" +     
                   "<entite>"+metier+"</entite>" +    
                  "<id_profil>"+id_p+"</id_profil>" +
                "<login>"+field1.value+"</login>" +
                "<password>"+field2.value+"</password>" + 
                "</user>" +
                "</body>" +
                "</soap:Body>"
                "</soap:Envelope>";


    xhr.open("GET", url); 
    xhr.send({username : "S-MINOS-BZT"});
    xhr.send({password : "3knqt7ew!"});
    xhr.setRequestHeader("WWW-Authenticate","Basic");
    xhr.setRequestHeader("Content-Type","text/xml", "charset=utf-8");
    xhr.setRequestHeader("Content-Length", soapRequest.length); 
    xhr.setRequestHeader("SOAPAction", "https://minos.altran.com/minosweb/classes/toolbox/minosgeneric/biztalk/soap/server/plugins/MOBCONGEST_query/wsdl/MOBCONGEST.wsdl"); 

    xhr.onload = function() {
        var doc = Titanium.XML.parseString(this.responseText);
        var type = doc.getElementsByTagName("login");
        Titanium.API.log(type.item(0).text);
    };    

    xhr.send({xml : soapRequest});

But it still doesn’t work. What is wrong ?

— asked August 22nd 2011 by lily
  • android
  • httpclient
  • xhr
  • xml
0 Comments

2 Answers

  • Save yourself a lot of manual coding and try out Suds.js from Appcelerator's own Kevin Whinnery. I used it in the past successfully for .NET web services.

    — answered August 22nd 2011 by Tony Lukasavage
    permalink
    0 Comments
  • Thank you for your answer. I'm sure it was useful in the past but in suds.js I saw for example
    xhr = new XMLHttpRequest();
    which we can not use now.We have to use
    var xhr = Titanium.Network.createHTTPClient();

    — answered August 23rd 2011 by lily
    permalink
    2 Comments
    • Hi Lily, Have you figured out what was wrong with your code above? I can't seem to connect to my webservice either.
      thanks.

      — commented September 4th 2011 by Mike
    • Hi i am working with Soap call: I want to do a soap call to fetch data from server. In my case i want to fetch data from sugarCRM framework. But unfortunately i m not able to pass multidimensional json format to the server via sudonclient object. I have tried the same thing in PHP and it returns me exaclty what i want. I want to pass a selected field array to the server for field selection in mysql result. It working fine in php but not in titanium using json format.

      PHP code $product_list_params = array( 'session' => $session, 'module_name' => 'Accounts', 'query' => '', 'order_by'=>'', 'offset' => 0, 'select_fields' => array('id','name'), 'max_results' => 1, 'deleted' => 0 ); //parameters array

      $product_list_array = $client->call('get_entry_list',$product_list_params); //make call

      Titanium Code

      var data='{"session":"'+session_id+'","module_name":"'+m_name+'","query":"","order_by":"name asc","offset":"2","max_results":"10","deleted":"0","select_fields":["id","name"]}';

      var list=JSON.parse(data); //parse data

      suds.invoke('get_entry_list',list,function(xmlDoc){

      //But here i dont got any response data in

      var retNode = xmlDoc.getElementsByTagName('return').item(0);

      });

      — commented December 28th 2011 by rajveer singh
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.