For my project course I'm thinking to develop an application in iPhone. I have some objective-c knowledge but I don't know what kind of API's Apple provide.
I've implemented RESTful web service and I was wondering if there is a way to access features of this RESTful API via iPhone. I mean, what kind of API's area available to send HTTP GET, POST, ... and to process JSON/XML data returned by web service?
Any help is very much appreciated.
All HTTP request methods (POST, GET, PUT, DELETE, etc…) are available with NSURLConnection.
You can parse XML with NSXMLParser and you can parse JSON with JSON-Framework (it's really good).
This tutorial may be helpful: Tutorial: Simple iPhone Rest Client
A great and widely accepted API for HTTP requests/etc is ASIHTTPRequest, here is the link. As far as XML parsing, you might want to take at the Apple provided NSXMLParser (note there could be external APIs for this, but I am unaware of them). Here is its class Reference
Related
I am bit confused regarding SOAP and REST and JSON
I do not know what step and what is the right way to implement this in objective-C
I want to send json data to a web-service via SOAP.
I should use RESTful or SOAP.
Any document or link would be appreciated.
Let me give you some advise out of personal experience regarding this.
A few things first, if you are in control of the web service I would recommend going for RESTful and returning and sending JSON data as parsing it using Objective-C is very easy.
There is a class library called SBJson you can use for the parsing of JSON data returned by the web service.
If you are not in control of what the web service will be returning and receiving, i.e. you didn't program the web service you can still use the SBJson classes for JSON data but I would recommend finding a XML library which you are comfortable in using.
http://www.raywenderlich.com is a great source of iOS tutorials with a in depth tutorial on XML parsing, which is used with SOAP.
The SBJSson library can be found at https://github.com/stig/json-framework/
Does these help?
This is one very common question asked again and again on stack overflow and I read so many answers about this but I am still bit confused.
I need to call the webservices from iPhone sdk.
Here are my questions:
I am not clear what response SOAP or REST return.Is there anything specific that if response is XML then we should use REST and if JSON we should use SOAP?
What is the role of ASIHTTP with SOAP and REST?
If I am getting XML response as
<oproduct>
<iid>113133791</iid>
<icategoryid>270</icategoryid>
<imerchantid>1547</imerchantid>
<iadult>0</iadult>
<sname>The Ashes / 1st Test - England v Australia - Day 1</sname>
<sawdeeplink>http://www.acbcd.com/pclick.php?p=113133791&a=111402&m=1547&platform=cs</sawdeeplink>
<sawthumburl>http://images.abcdd.com/thumb/1547/113133791.jpg</sawthumburl>
<fprice>69.99</fprice>
</oproduct>
Do I need to parse it by hand? or how do I handle XML response?
I got so many articles about REST and SOAP but no proper code to understand it.
I would be grateful for any help regarding these questions.
SOAP - "Simple Object Access Protocol"
SOAP is a method of transferring messages, or small amounts of information, over the Internet. SOAP messages are formatted in XML and are typically sent using HTTP (hypertext transfer protocol).
So SOAP has a standard how a message has to be sent.
Each soap web service can be defined with a WSDL(Web Service Definition Language) which is kind of a schema for the SOAP XML transferred.
There are many tools available to convert WSDL(your webservice definition) to native code.
One of the tool available for ObjC is Sudz-C (http://sudzc.com/) which convert the WDSL of any webservice to ObjC code to access the Web service.
Rest - Representational state transfer
Rest is a simple way of sending and receiving data between client and server and it don't have any much standards defined , You can send and receive data as JSON,XML or even a Text. Its Light weighted compared to SOAP.
To handle Rest in iOS there are many tools available, I would recommend RestKit http://restkit.org/, for handling XML and JSON both.
I would suggest you to go with Rest for mobile development, since its light weight
(Simple example, People correct me If I am wrong)
Ok, so you have a few different questions here:
REST is a way of accessing the web service. SOAP is an alternative way of accessing the web service. REST uses query string or URL format whereas SOAP uses XML. JSON and XML are two different ways of sending back data. SOAP and XML are usually associated with each other. For mobile apps, REST/JSON is usually the way to go. Easier to implement and maintain, far more telegraphic, etc.
ASIHTTP, as Bill notes, is a wrapper. There are other choices that do similar things depending on what you need. If you are using REST/JSON then NSURLConnection + SBJSON might do the trick, I like it personally.
If your SOAP service has an available WSDL you can use wsdl2objc to automatically build the code for your parsing and fetching. If it is a JSON service or no WSDL is available, I would recommend using SBJSON and simply parsing in the following way:
for (id jsonElement in repsonse) {
self.propertyA = [jsonElement valueForKey:#"keyA"];
self.propertyB = [jsonElement valueForKey:#"keyB"];
}
Hope that helps!
1) SOAP responses must be XML, and to return other formats you need to either embed them in the response XML (inefficient) or use SOAP attachments (difficult). SOAP responses are contained in a soap envelope tag, and there is usually an associated wsdl. If the XML you show is all you're getting, then it may not be a SOAP service. I see links in the XML so that is a good sign that they had REST in mind.
2) I haven't heard of ASIHTTP. A quick google, and it looks like its a third party library that wraps the http interfaces in iOS. It looks like you would use that to help you make the http requests, although I would suggest that it might not be necessary; you should evaluate using the http libraries directly.
3) You need to parse it somehow. You can do it by hand, but that is generally a really bad idea. XML can come in many forms and still have the same meaning, and if you don't support all forms your application could break in the future if the web service provider began to format their XML differently, even if its semantics were the same. You would use an XML api to read the XML. The DOM api will read it into a tree form for you, and you can use XPath to extract information out of the tree.
I am developing application in iPhone, Where i need to download and upload data from webservice. Please advice me which is the best class or Framework to achieve this and also please let me know which is the best xmlparser.
you can use asihttprequest and asihttpresponse for establishing connection use restful api and nxxml parser for parsing the data comes from server
thanks
NSXMLParser is a SAX parser included by default with the iPhone SDK.
TouchXML is an NSXML style DOM XML parser for the iPhone.
If your web service has the ability to return json, I would highly recommend doing so and using http://code.google.com/p/json-framework/. Especially if you have a complex XML document.
As for connecting to the service, it's pretty straightforward - all you need is a method to handle the connections. While there are 'frameworks' out there, it's as simple as creating a method such as "getDataFromService:(nsstring *)param1" and within that method issuing a request.
I think the bigger question you'll need to answer is how to authenticate with the service, if required. If the service uses OAuth, http://code.google.com/p/gtm-oauth/ is a great framework.
I am new to Three20 and have been trying to develop an iPhone app with Three20 for the past week. This app has to access to a xmlrpc server.
I know it is possible to receive responses in other formats like JSON.
But for requests, instead of the provided HTTP class TTURLRequest, is it possible to send request by XML-RPC?
I created three20 extention for XML-RPC connection.
It's on my three20 fork.
http://github.com/ngs/three20/tree/master/src/extThree20XMLRPC/
Please try this and feedback me.
Cocoa XML-RPC Client Framework appears to do what you want, although it uses the underlying NSURLConnection and friends that Three20 uses, not Three20 itself.
For the record, XML-RPC uses HTTP as its transport layer, so I don't see why you wouldn't be able to use it for that purpose in the first place; the main thing is writing a library that wraps the underlying HTTP transport pieces so you can invoke methods more transparently.
(I.e., you can set HTTP headers as well as the request method (GET, POST, PUT, etc.), and submit data in the body of an HTTP request, so everything is there to support it. Additionally, XML itself can be parsed via the NSXMLParser class, the Open Source libxml2 library, or other third-party solutions (e.g. TouchXML, which is built on libxml2).)
Lastly, there is another SO question regarding XML-RPC on the iPhone in general, although it has many of the same answers.
We have an iPhone application created by an external consultancy that we're planning to add card payment facilities to in a subsequent release.
We plan to host a service ourselves in order to process the payment stuff, with SSL encryption. We have in-house expertese for all of this apart from the (contracted out) iPhone bit.
Are there any specific gotchas that we should be aware of that concern designing web services for iPhones?
We'll be writing the web service in C# 3.5.
JSON data format is better to be converted into NSArray or NSDictionary objects. It's easier and faster to be parsed.
So, specifically for the iPhone, it's a lot better to consume JSON data. Unless if there's some technical complexity that JSON is unable to handle.
Check YAJL:
http://github.com/lloyd/yajl
There are Objective-C wrapper/implementations by gabriel in github and by MGTwitterEngine.
TouchJSON is another code that's simpler than yajl. You can convert JSON string into NSDictionary or NSArray object in 2 lines of code. But, it maybe slower.
I'm not sure there are really any special considerations. The iPhone should be able to communicate with most types of webservice.
I worked on an iPhone app that communicated to a RESTful webservice written in Java.
I imagine it's pretty straightforward across the board - there are plenty of libraries for parsing/generating XML or JSON formatted messages, the iPhone can handle HTTP authentication, HTTPS, caching, etc.
It's just down to your iPhone developer to get it right :)
For SOAP based web services I strongly suggest that you try gSOAP. This library does not support Objective-C, however it supports C and C++ and is certainly the most complete open source project to access SOAP based web service; it also outperforms all of the other libraries.
For Objective-C you may want to try wsdl2objc, but I am not sure if it provides support for SSL/TLS (gSOAP does).
Finally, REST based web services are easily handled using ASIHTTPRequest.