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?
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
-
Same thing here. I am also stuck at this point for some time…
-
@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
-
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);
});