iPhone Web Services Consumption Comparison
Introduction
This project showcases different transport formats and libraries to consume web services from an iPhone application. It features a server application, a command-line script that saves the output of the server application in different formats, and an iPhone client application (compatible with iPhone OS 3.0 and higher).
The server application (written in PHP) reads a MySQL database (Server/data/schema.sql) and outputs data in the following formats:
- HTML
- JSON
- YAML
- XML (arbitrary format)
- SOAP
- Property list
- Binary property list
- XML property list
- CSV
- Protocol Buffer (Google)
For each output format, there is a single βFormatterβ subclass in the Server/formatters folder. A static method in the FormatterFactory class returns the formatter that corresponds to the requested output format.
Future Extensions
In future versions of this project, the following formats and libraries could be integrated:
- MessagePack
- Apache Thrift (StackOverflow article about how to integrate with the iPhone)
- BERT
- Apache Avro
- Open Network Computing Remote Procedure Call (ONC RPC) aka Sun RPC
Libraries Used
The project uses several different libraries:
For the server:
- cfpropertylist β A PHP Implementation Of Appleβs plist (PropertyList).
- NuSOAP β SOAP Toolkit for PHP.
- spyc β A simple YAML loader/dumper class for PHP.
- pb4php β Protocol Buffer for PHP
For the iPhone client:
- AFNetworking β a very fast, NSOperation-based networking library
- NextiveJSON β a very fast JSON parsing library
- ASIHTTPRequest β wrapper around the CFNetwork API, no longer maintained
- json-framework β A strict JSON parser/generator for Objective-C.
- JSONKit β A Very High Performance Objective-C JSON Library.
- YAJL-objc β Objective-C bindings for the YAJL parser.
- BSJSON β A simple JSON parser in Objective-C.
- touchcode β Repository of iPhone and iPod Touch source code.
- cCSVParse β A CSV parsing library in Objective-C.
- TBXML V1.3 β XML Parser by Tom Bradley.
- KissXML β KissXML is a replacement for Cocoaβs NSXML cluster of classes. It is based on libxml.
- TinyXML β TinyXML is a simple, small, C++ XML parser that can be easily integrating into other programs.
- gdata-objectivec-client β XML support classes included in the Google Data APIs Objective-C Client Library.
- APXML β NSXMLDocument βsubstituteβ for iPhone/iPod Touch.
- ProtocolBuffers β Objective-C Protocol Buffers for OSX and the iPhone.
- AQXMLParser β Another parser for XML in Objective-C.
- InAppSettingsKit β Library allowing to access the current setting bundle from the application.
YAML in Cocoa
For parsing YAML in Cocoa, the code in this page was adapted, removing dependencies on the Cocoa AppKit framework (not available on the iPhone).
If you want to compile the YAML::Syck library with Fink, follow these steps:
- Install Fink on Mac OS X 10.6 from source following these instructions (there is no binary installer available for Snow Leopard at the time of this writing).
- Type β/sw/bin/fink install syckβ to install syck.
- The Xcode project should now compile without problems.
To avoid these steps above, this project includes a version of libsyck.a already compiled as a βfat binaryβ format for both ARM (iPhone OS) and Intel (Simulator) processors.
SOAP in Cocoa
The wsdl2objc tool was used to generate Objective-C (Cocoa) code from the serverβs WSDL. This code was later adapted to parse the array returned by the server.
Installation
- Set up the server:
- Upload the βServerβ folder contents via FTP or other means.
- Create a MySQL database.
- Import the βServer/data/schema.sqlβ file into the database. This will create a βdataβ table in the database.
- Change the settings in the βServer/data/database.phpβ file to access the database (server, username, password).
- Set up the client:
- Open the βClient/Client.xcodeprojβ project in Xcode.
- Compile the project.
- Execute the client, which will connect to your server and retrieve data.
- If required, change the URL of the remote data tapping the βSettingsβ button in the interface.
Other Links
- The sample data generated in this example comes from http://www.generatedata.com/.
- cfpropertylist in Ruby β Read, manipulate and write both binary and XML property lists as defined by Apple.
- PyYAML β PyYAML.org β the home of various YAML implementations for Python.
- plistlib β Generate and parse Mac OS X .plist files from Python.
- Discussion about CSV parsing in Objective-C
- soapUI β Cross-platform tool for testing SOAP web services.
- How To Choose The Best XML Parser for Your iPhone Project β by Ray Wenderlich, iPhone Developer and Gamer.
- iPhone Programming Tips: building Unix software β The bundled libsyck.a static library (fat binary for both ARM and Intel) was created using the information in this page.
- XML Benchmarks β libxml2 sax
- Using the SAX Interface of LibXML
- libxml2 Push Parsing
- web services with cocoa surprise
- iphone plist tutorial
- Comparison of data serialization formats
- Property list β Wikipedia page.
- Protocol Buffers β Wikipedia page.
- Protocol Buffers Developer Guide
- XMLRPC framework used by the WordPress iPhone application.
- AQXMLParser == Big Memory Win β Article about the AQXMLParser library.
- Results of Northwind database rows serialization benchmarks run at 06/02/2010 β Interesting analysis of serialization performance using .NET libraries.
The application icon and splash screen have been adapted from this picture.
License
This project is released with a liberal BSD license. See the LICENSE file for details.