Titanium Community Questions & Answer Archive

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

Just call me a noob, but stil having problems with SOAP request...

I have a SOAP web service, written in C#, that I am trying to call using Titanium. I have tried several of the examples provided by otherin the dev center, but just can't seem to get it to work.

Anyone have a simple (start to finish) example of calling a SOAP web service and printing out the result of a node.

I am just pulling my hair out and it is just probably something simple that I am missing. I have been using Mike Brophy's code found in github, but can't seem to get it to work. I have also tried to work in the snippets others have provided (thanks much!), but nada.

Little help?

— asked March 26th 2010 by Chad Tanner
  • createhttpclient
  • kitchen
  • service
  • sink
  • soap
  • web
  • xml
0 Comments

4 Answers

  • Accepted Answer

    I am using the 'suds' javascript SOAP client http://github.com/kwhinnery/Suds
    But I had to modify 2 functions first:

    Change the getXHR function from this

      function getXHR() {
        var xhr;
        if (window.XMLHttpRequest) {
          xhr = new XMLHttpRequest();
        }
        else {
          xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xhr;
      }
    

    to this

      function getXHR() {
        return Titanium.Network.createHTTPClient();
      }
    

    And next change the xmlDomFromString function from this:

    function xmlDomFromString(_xml) {
      var xmlDoc = null;
      if (window.DOMParser) {
        parser = new DOMParser();
        xmlDoc = parser.parseFromString(_xml,"text/xml");
      }
      else {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(_xml); 
      }
      return xmlDoc;
    }
    

    to this:

    function xmlDomFromString(_xml) {
      xmlDoc = Titanium.XML.parseString(_xml); 
      return xmlDoc;
    }
    

    You can now do a SOAP request.

    I use this xml result for the example

    <SampleResult>
        <property>value</property>
    </SampleResult>
    

    You can retrieve the property value by doing:

    Titanium.include('suds.js');
    
    var suds = new SudsClient({ 
        endpoint: "http://domain.com/service.asmx",
        targetNamespace: "http://namespace/" 
    });
    
    var args = {propertyName: 'propertyValue'};
    
    suds.invoke("SampleMethod", args, function(xmlDoc) {
      var propertyList = xmlDoc.documentElement.getElementsByTagName("SampleResult");
        var value = propertyList.item(0).getElementsByTagName("property").item(0).text;
        alert(value);
    }
    

    I hope this helps :)

    Leander

    — answered April 29th 2010 by Leander Stolk
    permalink
    2 Comments
    • Hi guys!
      Am just reading this thread i found out that it's a similar problem to what am facing right now. How do retrieve all the values of the following XML file.

      <Result>

      <SampleResult>
      <property0>value</property0>
      <property1>value</property1>
      <property2>value</property2>
      <property3>value</property3>
      </SampleResult>

      <SampleResult>
      <property0>value</property0>
      <property1>value</property1>
      <property2>value</property2>
      <property3>value</property3>
      </SampleResult>

      </Result>

      — commented June 14th 2011 by Etukeni Emmanuel Ndechaobase
    • Leander, i have tried all of your suggestion posted here but not able to get the output from the SOAP webservice http://www.webservicex.com/globalweather.asmx, which is very similar to the currency converter available in suds.js. Have changed the parameters,actionMethod, endpoint,targert but not able to retrieve . pls help me out here.

      — commented February 1st 2012 by Amarnath Rajasekaran
  • Same thing here. I am also stuck at this point for some time…

    — answered March 31st 2010 by Alexandros Binopoulos
    permalink
    0 Comments
  • @Chad/Alexandros - I was wondering if you folks made any progress calling the SOAP web service written in C#?

    I am fairly new to web services. I've noticed other's talk about using WCF + JSON for their web services and I was wondering what your take on that is?

    • Johnny
    — answered May 3rd 2010 by Johnny Basu
    permalink
    0 Comments
  • 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);

    });

    — answered December 28th 2011 by rajveer singh
    permalink
    0 Comments
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.