Drupal 6: Using Appcelerator Titanium to create an iPhone application to communicate with a Drupal site via SOAP (suds client & nusoap server)
Let’s start with the SOAP server instance. I created a module called “nusoap”, and copied the lib folder from nusoap into it. I then created a file in the module’s directory called “soap-server.php” and added the following code. For the sake of this article, I did not include the rest of the Drupal module’s code.
The above code registers one soap server method “login_fetch_data” which accepts the arguments (name and pass), loads a full Drupal bootstrap, authenticates the user, and returns back the user’s uid. By browsing to the soap server file directly, I can see nusoap’s WSDL definition: (example: http://drupal.vm/sites/all/modules/custom/nusoap/soap-server.php)
To test if the soap server method was working, I used the follow PHP code snippet (which I pulled out of a test page callback):
I then created a new Titanium iPhone project. In the Resources directory, I created a directory called “soap-test-includes” to contain the suds.js library, and the soap.js file which uses this library. The suds.js file is available in the Kitchen Sink Titanium project, if you choose to import it.
I added the following code to the app.js file:
And I added the following code to the soap.js include file:
When I build and run the project, the iOS Simulator opens and shows the results of the soap connection!