send json data to a web service via SOAP - iphone

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?

Related

Consuming a Webservice and Parsing the XML Data in iphone

I am working on a application where my requirement is to consume a webservice and capture the xml data by parsing it. I am not sure about how to consume a webservice and capture the xml data. I am not able to decide which Parser to use to parse the XML. My webservice goes this way "xxxxxxxxxxxxxxxxxxxxxx/test/getTestSchema.cfm?sid=10335&course=ALZ_PATIENT&lesson=991&examtype=R&nStartRow=1&nEndRow=25&videoid=5" . Can anyone please help me out on how to consume a webservice and parse it with a sample code? That would be very helpful. Thanks a lot
We once had used sudzc to consume SOAP based web service in one of our apps. Then used TouchXML to parse the XML returned. It was quite easy and worked very well. sudzc takes WSDL and actually generates code to consume the web service! TouchXML tutorials are abundant on the net.

How SOAP and REST work with XML/JSON response?

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.

Which is the best Class for Download and upload data from iPhone?

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.

How to start use webservice

i want to read and write data to a website (server on web) and don't have any information about webservices and other things that related to it
Does anybody have any idea about how to start it (mean offer complete books,papers,tutorials,websites,… or what should i learn at first mean is it necessary to learn xml,soap,... and other things)
Thank you
I've used Google App Engine with great success. You would format your data to output as JSON and use an iPhone library to read it. I've used this one (though Touch JSON seems to be more popular).
Read about REST, ROA and AtomPub. Thats got me started. I'm about to implement some webservices in WCF (WCF now acts like a RESTFul webservice, but you can also use plain old SOAP). Before I got to WCF, I experimented with RoR. RoR uses REST "out-of-the-box".

How can I connect iPhone and web service and get XML data?

I know how to connect to web server using an iPhone but now I have to connect the iPhone to a web service. I don't know how to do it and there is no demo or class available online.
Does anyone have any ideas?
You might find this tutorial, called Intro to SOAP Web Services useful. He shows how to package a request, send it to a web service, and read the response.
If you need some help with XML parsing, there is the TouchXML library which will give you a nice xml "document" to work with. Just be cautious of memory usage.
If you have to parse large XML message this tutorial about libxml and xmlreader in Cocoa will show you how to parse XML with the lower-level event-style parsers.
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
You can use these 2 lines which return the response of your HTTP request. You don't need any configuration. This code is usefull if you try to access a PHP scritp for example. After you just have to parse your result.
NSURL *URL=[[NSURL alloc] initWithString:stringForURL];
NSString *results = [[NSString alloc] initWithContentsOfURL :URL];
In my opinion, you have two options :
Use a third party library. You can try wsdl2objc. It didn't work for me, but it is under active development so it improves every day.
Use a raw HTTP connection and handle every request/response. This is the way I followed. It is hard, so I'd also like to know a better approach.