Wednesday, February 3, 2010

Web Services and iPhone

One of the thing that really bugs me as an iPhone OS Developer is when I mention the term "web services" to a client or someone you need to convince about the job at hand.
The thing is to understand here is that how do we transfer data between an application thats running on the user's device and my application running on the user's computer. Well frankly we don't have a direct solution for this problem.

Let me delve into the concept and the need a little bit more.
The keyword here is 'interoperability', Internet as we all know is ever expanding. We have newer Platforms, Programming Languages, Operating Systems introduced every now and then; So the need to communicate across programming languages and operating systems has brought the concept of web services to us.
A web service can be a list of methods/procedures that can be utilized inter or intra programming languages, OS, hardware that's being used to develop them in the first place.
Once a web service is deployed on the internet it can be used by any client using the internet standards XML,HTTP.

There are other fundamentals of web services like XML,SOAP,WSDL and UDDI that can be googled for clarity.

Coming back to the moot point now, iPhone programming does not provide a direct way for third party developers to transfer data between the user's computer and the device.
To cite a few examples here:
  • A PDF viewing application needs a way to get PDF files to the device.
  • An iPhone OS application with 'free' and 'pro' versions needs to transfer data between these versions.
  • An iPhone application wanting to share live feeds on its interface from a website or an API.
iTunes does this for various system-supported data types (movies, music, contacts, and so on) but there's no way for you to piggyback on top of that support.
The only way out is to implement your own transfer mechanism based on TCP/IP networking. You gotta be familiar with network programming otherwise this could be a bit dodgy.
Any networking code must deal with a set of fundamental problems like,
  • Reliability : All I can say is TCP is the answer here. It is the best protocol for data transfer.
  • Bandwidth : Amount of data that can be transferred.
  • Latency : Expressed in round trip time from destination to source after data transfer.
  • Attacks : This is always an area of concern when you connect to a network.
iPhone OS is less vulnerable to this sort of problem than Mac OS X because iPhone OS puts strict limits on what memory within your process can be executed as code. However we must not get complacent about it! Malicious Attackers are always looking for new ways for exploitation.
Some of these problems can only be solved in the context of your overall architecture.

It is recommended to become familiar with the fundamentals of security layer and its working.

Solutions to the two network designs:

Centralized : single server on public internet and all clients connect to the server.

iPhone OS devices currently support three link layers for networking (WWAN, Wi-Fi, and Bluetooth), and all of them present challenges for peer-to-peer use.

Solutions for centralized server designs:
  • Service Directory : process whereby peers learn about the existence and address of other peers.
  • Authorization : your application is the guardian of the user's data.
  • Wire Privacy : I recommend that you err on the side of caution and consider all user data to be personal.
Solutions for peer-to-peer designs:
  • Bonjour services
  • Bluetooth
  • Wi-Fi
  • On-The-Wire Privacy
  • Gamekit
  • Creating Identities
  • Authorization
  • NSNetServices & CFNetServices
Some of the above mentioned services might require iPhone OS 3.0.

FTP is a protocol for file transfer and its high-level goal is to transfer files from one machine to another.

AFP is the default sharing protocol on Mac OS X. This could be tricky though, AFP is quite a complicated protocol, and there's no high-level API for it on iPhone OS. Moreover, AFP is a very Mac-centric protocol, which is a problem if you want to sell your application to users of other platforms.

Although having said all that about MAC and iPhone's networking technicalities and capabilities, there is one notable omission in the iPhone SDK is the lack of a core web services framework. iPhone's emphasis on internet connectivity is all the more surprising that there is no native framework for SOAP web services.

So as developers we are not left with any choice but to roll on our own.

For iPhone OS to use a framework interacting with SOAP without one is not that difficult; its similar to REST-ful web service.
Data is POSTed over HTTP at a particular endpoint URL, and the application translates the results into native objects on run-time.

That's all for now!! Will be updating soon about the SOAP and JSON framework as I learn about it. :)

Till then keep your code clean and god bless.

No comments:

Post a Comment