iPhone Programming Tutorial - Intro to SOAP Web Services
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
This tutorial was contributed by Dave (AKA Clarke76) on the Forums.
WebSite: http://viium.com
-Main project on site is eDuo. A .Net app that connects to OWA Exchange and forwards to IMAP account. Free program for those who can’t use Active Sync
Important Links:
[WebService] http://viium.com/WebService/HelloWorld.asmx
http://developer.apple.com/documentation/Cocoa/Conceptual/XMLParsing/XMLParsing.html
http://www.w3schools.com/soap/default.asp
-After creating our XML data / SOAP request, we create a URLRequest. We add HTTP Header values, those values you read from the WebService.
-We set the HTTP Method to POST
-We set out HTTP Body to the xml file we created
-We then create our connection, using the request we just setup.
-Once the connection is setup and delegate is set to self, we need to setup out connection delegate methods.
-The first method just makes sure it can make a connection. If it can, we make sure we have no data in our Data set so we clear it.
-Second method is called when re receive any data. If we do receive data, we just append it to our data set.
-Third Method handles any errors and releases our data and connection if an error occurs.
-Fourth Method: We take the data and create a string for Logging reasons, then release the string.
-We check to make sure an instance of xmlParser does not exist, if it does we release it.
-Create a new instance of xmlParser, set the delegate to self, want to resolve external entities, and start our parsing.
-release our connection and Data
Now we need to our our delegate methods for NSXMLParser
First method we are check the start of elements. If our element equals “HelloResult” we set our BOOL to true. Second method records any data between an element if our BOOL is set to true. Third method checks for our closing element. Once found sets our greeting, releases our MutableString, and set our BOOL back to false.
If you have any questions or comments, please leave them in the comments of this post. You can download the sample code here.
- Posted by Brandon on 3 Nov 2008 in iPhone Programming Tutorials
- Digg |
- Del.icio.us |
- Stumble |
41 Responses
Dan Says:
November 3rd, 2008 at 8:49 pm
This is a great tutorial! I was looking for an intro into calling web services with the iPhone SDK, and this was a great starter.
Keep up the great work on this site!!!!
iDeveloper Says:
November 4th, 2008 at 9:34 am
Hi
I was using something similar taking reference from http://kosmaczewski.net/2008/03/26/playing-with-http-libraries/
But this method causes a problem when using on the device. It works fine on the simulator though. I’ve been trying to figure out the reason for sometime now.
The problem with running it on the device is that the content length logged at the server is 0 if you send the SOAP envelope as the body of the request using POST. Any ideas why this would happen though?
Mark Says:
November 5th, 2008 at 12:05 am
Thanks for the tutorial. Just what I was looking for. Just one question (not about the tutorial), how do I setup custom code snippets? Cheers
sindhu tiwari Says:
November 15th, 2008 at 12:09 am
Hi i have seen many tutorials on connecting a iphone application to a web Service this is one of the best , I want to know how to send parameters to a web service something like , There is a method which adds to given numbers and returns the result , those two numbers are the arguments of function now how to pass those parameters i will be thankful for the reply
sindhu tiwari
maqish Says:
November 21st, 2008 at 1:18 am
i believe NSXMLParser is not available on the device but usable on the simulator. that is why iDeveloper had some issues
zebrum Says:
December 7th, 2008 at 7:44 pm
How did you set up the text macros? Those look really handy.
lakshmikanthreddy Says:
December 26th, 2008 at 6:20 am
hi ,
awesome sample which u have put upon WebServices , but one small query , i am unable to run this sample can anyone guide me from the scratch for how to run this sample .
thanks in advance.
Alice Says:
January 3rd, 2009 at 9:05 am
You can barely hear the audio at all… even at full
volume.
*PLEASE* speak into the mic.
Arash Says:
January 5th, 2009 at 10:56 am
Thanks a lot for your great tutorial,
I am writing an iphone application that will consume a .net webservice (basically it will get the list of radio channels with their url and an image)
I wrote the ,net webservice and it is working fine but when I am trying to get the xml data in iphone I see that tags are
not displayed correctly in debugger “” are shown like >< do you have any idea about this?
Jeremy White Says:
January 15th, 2009 at 12:46 pm
Even running the sample code, I get a warning in the method
parser didStartElement:
for the following line (line 100 in sample)
recordResults = YES;
Message is as follows:
warning: assignment makes point from integer without a cast.
Any ideas what this is about? Anyone else seeing this warning?
Uffe Koch Says:
January 19th, 2009 at 6:15 am
Good tutorial, well done.
The warning is due to the superfluous * in the definition of recordResults, was:
BOOL *recordResults;
should be:
BOOL recordResults;
rubennm Says:
January 26th, 2009 at 6:06 pm
Forget it. Finished reading everything, saw some examples, created the needed soap messages at runtime. Thanks for a great tutorial
Pablo Says:
February 3rd, 2009 at 5:40 am
Hi! Great tutorial. By the way, i’ve been working on it and i wonder if you could answerme one question. Would it be posible to create a connection at the applicationWillTerminate method and wait for connectionDidFinishLoading to finish?
Thank u!!
Rajiv Says:
February 20th, 2009 at 3:56 am
Thanks for the useful tutorial…i have tried it. It works great with Web Services developed with Dot Net 2.0 framework. I have to consume webservice developed in Dot Net Framework 3.5, but its not getting any response from the server at the connectiondidfinish delegate method. The HttpConnection Status i m getting is 400 ( bad syntax ).
The webservice is returning data from another web client.
Can you please suggest me something to try.
james Says:
February 21st, 2009 at 6:09 pm
Thanks for the tutorial..
how do we see the methods by writing ” @url “. what is the shortcut for it
Andreas Says:
February 24th, 2009 at 1:20 pm
I tried to receive data from a webservice which is almost the same as shown in the example. But I have an issue when coming to parsing the data from the response from the server.
The response looks like this:
string
The issue in this case is that the string that is returned from the server is another XML file, where the format is not as it should be.
The is >
When trying to parse this string with the NSXMLParser function, I am not able to parse it as I want to due to the brackets. Looked for a solution for this, but only found something called “CFXMLCreateStringByUnescapingEntities”. But this give me another problem, something called CFStringRef. I do not know how I can use this function to get the XML format from the string, so it is possible to parse the data and present it in the application.
As I understand the NSXMLParser needs a NSObject, not a string, and my question is then, how can I use the unescaping entities function and use it in the parser?
Thanks in advance.
Andreas Says:
February 24th, 2009 at 1:25 pm
Saw that a lot of the text is missing in my previous post.
But maybe it is shown in this:
string
The issue in this case is that the string that is returned from the
server is another XML file, where the format is not as it should be.
The is & gt;
sindhu tiwari Says:
March 9th, 2009 at 4:49 am
Hello Dude , Thanks for such a good blog .
My aim is to consume a PHP driven webservice into my Iphone project .. can u provide some stuff on that .. i know that underlying architecture doesnt makes any difference but still for me I AM DUMB IN PHP .. headers and Soap Message will be enough for me ..
Have a wonderful time ahead
Thanks and Regards
Sindhu Tiwari
JG Says:
March 22nd, 2009 at 3:27 pm
How would you go about passing username/password if the XML Service was on a secure site that requires HTTPS and authentication?
Laurent Says:
March 23rd, 2009 at 6:54 am
Hi !
Thanks for this tutorial.
I’m new to iPhone and Apple programming (I come from .NET world) and I can’t believe it’s so complicated to consume web services in ObjectiveC… isn’t there a simpler way to do that ? With Visual Studio I can do that in 30 seconds.
Thanks in advance for your answers.
Laurent
my Says:
April 20th, 2009 at 5:00 am
Hey,
Tutorial is great. I just want to ask, how do you autocomplete the delegate methods?
Ashwani Says:
April 21st, 2009 at 7:35 am
Hi
Thanks for this articles
I need one help in parsing XML
Can any body tell me how to convert this XML into dictionary
of the format
key(son) value(NSArray of grandsons)
WSDL .. iphone ? - iPhone Forum - alles over de Apple iPhone en iPhone 3G Says:
April 21st, 2009 at 12:43 pm
[...] SOAP is niet meer dan een http post geformateerd in XML dus je kunt het gewoon doen met NSURLConnection. Nadeel is natuurlijk dat je geformateerde XML zelf moet maken ipv dat je deze uitleest uit de WSDL. Hier heb je een tutorial die voor mij werkte: iCodeBlog Blog Archive iPhone Programming Tutorial - Intro to SOAP Web Services [...]
ashwani Says:
April 22nd, 2009 at 6:26 am
Hello :
I used the code posted in this thread. It helped me a lot.
But now I am facing an issue please help me.
I want to send data to web service in the form of xml like
<son>
<child name=”XYZ”>
</son>
and get back some information related to child.
But 0 byte response is received please help me in fixing this issue
Thanks in advance
Sambha Says:
April 26th, 2009 at 2:37 pm
Excellent tutorial and blog. Its my favorite one now
Thanks a ton for sharing your knowledge.
Cole Says:
May 1st, 2009 at 3:04 pm
hi there! this is a great tutorial!!
question. what method can i use to return the value in the request below:
string
I see that NSLog(soapResults); returns what i want….but i’m not sure how to use it to catch if/when a request returns “false”, then i want to create a UIAlert telling the user their login failed. thanks!!
David Says:
May 3rd, 2009 at 8:05 pm
Hi guys,
I downloaded the source and tried to open the project file in xcode. I have the latest xcode running (only downloaded it around a month a go).
I get a warning about this project having been saved under a “newer” version of xcode and when it opens the project there are three files that are colored red which it obviously cannot find:
Foundation.framework
Hello_SOAP.app
UIkit.framework
Any ideas?
ParaSite | Uploading Says:
May 23rd, 2009 at 2:43 pm
[...] with the iPhone that I was at a total loss where to start. I began eyeing Dave’s tutorial on SOAP Web Services, but that just freaked me out a little too much. I needed something laid out simply first before I [...]
John Says:
June 5th, 2009 at 2:53 am
Hello I am new to Iphone development and your tutorial helped me too much. Thanks for your this tutorial.
Also please let me know how you get code sense window doe delegates for eg in video you typed “@url” and then delegate code window will appears how?
Thanks in advance.
NeedSomeAdvice Says:
June 18th, 2009 at 2:40 pm
Well i figured out how to read one value from an xml file from ur tutorial, but right now at the moment im doing a project that needs me to traverse through a tree of data and pick out certian keywords and display their values and since i learned ur way of retrieving xmldata i thought i come to you first.
-thanks
Niketa Says:
June 24th, 2009 at 4:13 am
I have used this example in my application. Its working properly on simulator. but not working on iphone device. Its giving “Connection error”. I have checked for wifi connection. its working properly.
for PHP guys to use the same feature Says:
July 2nd, 2009 at 4:36 am
SORRY..!!!!!!
all the strings are stripped off…






