Thursday, October 25, 2012

What is a web service and what does it do.

First of all i apologize for writing this post so late i should have wrote it earlier when i wrote my first post of web service.


Many Freshers who come in iOS development are keen to know what is a web service and why to use it ? So in today's post i am going to clear the air a little bit.

What is a web service : A web service (ws) is a media where you request some information from the server and the server processes your request and provides you with the appropriate response.

The response can be in various formats like XML (Extensible mark up language), JSON (JavaScript Object Notation), CSV (comma separated value)

Example: If you want to display the name of your facebook friends in a table view then what you do is you call the facebook API. You call the required service and get the list of your friends from facebook.

Similarly if you want to get the details of any one of your friend from the list the you call another facebook service which will get the information about your friend.

Another example is google places API where you pass the category name as a parameter like banks, hotels etc and your current location and you get the list of banks or hotels near you.

How to know the response format of the web service: The web developer who has created the web service will tell you regarding the response format. The response format which is mostly used for hand-held devices is JSON since its simple and faster.

Classes for sending request in iPhone : The class named NSURLConnection will help you out in sending a request to the server and it will give you the response in it's delegate method named "connectionDidFinishLoading". But before creating the object of this class you need to create a request object of class type NSMutableURLRequest. You may visit this link for one of my sample demos for web service

Response Issues with web service : Many time what happens is that when the iOS developer parses the web service an HTML response is received instead of JSON or XML, this is because the web developer who was coding might have forgot to turn off his log printing (Just like NSLog that we have) or their might be an SQL / ORACLE exception.

Myth in the minds of web service developers : Many web service developers in the beginning think that making a ws for mobile is somewhat different than the ws they create, i would like to inform those developers that its the one and the same thing the only difference is in the response format where you need to send JSON or XML instead of a String or an Integer.

I hope that this has cleared some air in the minds of freshers and web service developers, if you have any queries then feel free to ask them as a comment to me via comment or mail.

Until then Happy iCoding and have a great day...

5 comments:

  1. Hi Ravi, Thank you for sharing this informative article. This is one of the best article I've read. you may also visit us for listing web service.

    ReplyDelete
  2. hi, friends..how do I get responses from ios web servis( multiple parameter)..and showing on the texfield

    i dont want to only for one parameter ..please multi-parameter..

    sample parameters are : name , surname , age , address ..

    ReplyDelete
  3. i had alot of questions regarding web service in mind and what exactly its used for which are now clear! all credit does to you for solving my problmes, thanks for sharing.

    ReplyDelete