views:

927

answers:

5

Hello,

We are going to set up a solution where the iPhone is requesting data from the server. We have the option to decide what kind of solution to put in place and we are not sure about which way to go.

Regarding SOAP I think I have the answer, there are no really stable solution for doing this (I know there are solutions, but I want something stable).

How about REST?

Or is it better to just create our own XML? It's not going to be so complicated reguest/respons-flow.

Thanks in advance!

+2  A: 

You are not saying how complex your data structures are and if you actually need state handling.

If you want to keep your network traffic to a minimum, while still keeping some of the structured features of XML, you might have a look at JSON. It is a very light weight data encapsulation framework. There are some implementations available for iPhone, for instance TouchJSON

Claus

Claus Broch
Not complicated, and I don't think I need state handling.
Nicsoft
And just to add to Taums answer, TouchJSON will provide you with a NSDictionary of the parsed data.
Claus Broch
POX and JSON are about the same in bandwidth, I think protocol buffer might be better for saving bandwith
vtd-xml-author
I also agree with Protocol Buffers, really an interesting protocol and low payload. But the iPhone library I found (see my answer below) is a bit in an "alpha" stage. The whole idea of Protocol Buffers is really promising though.
Adrian Kosmaczewski
+1  A: 

I would go with simple HTTP. NSURLConnection in the Cocoa libraries make this pretty simple. Google Toolbox for Mac also has several classes to help parsing URL-encoded data.

Barry Wark
+3  A: 

XML Property-lists (plist) are also a common way to serialize data in Cocoa. It is also trivial to generate from other languages and some good libraries exist out there.

Taum
+4  A: 

REST is the way to go. There are SOAP solutions, but given that all people end up doing with SOAP can be done with RESTful services anyway, there's simply no need for the overhead (SOAP calls wrap XML for data inside of an XML envelope which must also be parsed).

The thing that makes REST as an approach great is that it makes full use of the HTTP protocol, not just for fetching data but also posting (creating) or deleting things too. HTTP has standard messages defined for problems with all those things, and a decent authentication model to boot.

Since REST is just HTTP calls, you can choose what method of data transfer best meets your needs. You could send/receive XML if you like, though JSON is easier to parse and is smaller to send. Plists are another popular format since you can send richer datatypes across and it's slightly more structured than JSON, although from the server side you generally have to find libraries to create it.

Many people use JSON but beware that it's very finicky about parsing - mess up a character at the start of a line, or accidentally get strings in there without escaping "'" characters and there can be issues.

Kendall Helmstetter Gelner
+4  A: 

I've created an open source application for iPhone OS 3.0 that shows how to use REST & SOAP services in iPhone application, using XML (using 8 different iPhone libraries), SOAP, JSON (using SBJSON and TouchJSON), YAML, Protocol Buffers (Google serialization format) and even CSV from a PHP sample app (included in the project).

http://github.com/akosma/iPhoneWebServicesClient

The project is modular enough to support many other formats and libraries in the future.

The following presentation in SlideShare shows my findings in terms of performance, ease of implementation and payload characteristics:

http://www.slideshare.net/akosma/web-services-3439269

Basically I've found, in my tests, that Binary Plists + REST + JSON and XML + the TBXML library are the "best" options (meaning: ease of implementation + speed of deserialization + lowest payload size).

In the Github project there's a "results" folder, with an Excel sheet summarizing the findings (and with all the raw data, too). You can launch the tests yourself, too, in 3G or wifi, and then have the results mailed to yourself for comparison and study.

Hope it helps!

Adrian Kosmaczewski
Very interesting analysis. Metrics and facts often beat any "in my opinion" arguments.
Claus Broch