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.
Related
I am trying to create a Rest web service running on iPhone; I've done my initial research and found
CocoaHttpServer and TouchCode json parser, is there any library / sample code which binds these together into a Rest endpoint?
If it does not exist, how do I go about writing one? Any reference to some kind of design document etc. will really help.
I'm using CocoaHTTPServer and the iOS builtin JSON libraray to have a RESTful service in iVocabulary. First I wrote a lengthy Connection class (the core for handling requests in CocoaHTTPServer) myself. But parsing the URL was kind of complicated.
So I wrote a more generic Connection class that routes HTTP requests to different blocks for different URLs and different HTTP methods. The URL can contain parameters (with : as prefix), that get parsed. That's not a generic REST service per se, but I added (for example) a block for the url "/rest/:entityname" that fetches all Core Data objects of the given entity.
You can find that router implementation in my fork of CocoaHTTPServer on github: https://github.com/chbeer/CocoaHTTPServer
Another router implementation: https://github.com/mattstevens/RoutingHTTPServer
Check RestKit for working with Restful web services.
http://restkit.org/
I recommend RestKit, I have used for over a year now and love it. However I recently learned about AFNetworking from some colleagues that claim it's very lightweight and thus prefer it as an alternative to RestKit, so I am giving it a try soon.
My original question regarding Consuming Custom Request Methods with Android seems to have garnered very little attention -- I have converted it to an Android specific question
So, quite simply, with iOS5 development, is it possible to consume custom request methods?
If so, how.
The "standard" set of request methods, as per RFC-2616 are:
GET
PUT
POST
DELETE
TRACE
CONNECT
I would like to add another, called SEARCH. On the API, using PHP or Java, this is easy to implement in PHP. The consumption of this new request method is proving to be a challenge for an iOS developer.
Does anyone have any references to working examples or frameworks that will support a custom request method, such as SEARCH, or FOOBAR?
ASIHTTPRequest allows it: http://allseeing-i.com/ASIHTTPRequest/How-to-use
Check out the 'PUT requests and custom POSTs' section.
[request setRequestMethod:#"SOME_REQUEST_METHOD"];
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.
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
I'm working on an iPhone project that needs to receive data from a PHP script during execution. My first thought was to use sockets/streams on either end to connect the two, but I am having trouble finding information on how to do this from the iPhone side.
Has anyone been down this path that could point me towards some useful resources or offer some advice? The official documentation seems to be geared more towards desktop apps and uses code that doesn't seem to be supported on the iPhone (namely NSHost).
Update: The intended use of this app is to receive log messages from an executing script, so I can't use a simple HTTP request with JSON or XML. Many cases will involve the page being loaded by another client, where the script would relay/push log messages to the iPhone.
Polling is evil. You'll chew through batteries doing that.
You might consider running an HTTP server on the iPhone. Check out this blog post; it has an implementation of an HTTP server in Cocoa as well as example code for using it for two-way communication.
The PHP CURL library (can't link it because the site doesn't trust me yet, just search php.net for it) is a (relatively) simple, easy way to make http requests with a PHP script.
Why don't you just use HTTP? Create an ad-hoc protocol with XML or JSON, use POST for upstream data transmission. I'm a fan of JSON for this sort of thing, personally. The PHP, instead of returning a webpage in HTML for rendering, should just return your data in a JSON format.