Subscribe ( RSS )

iPhone Programming Tutorials


Where To Eat? Find restaurants using GPS.
Intimate Secrets
Dynamic photo effector
GPS Where To Go? Find Points of Interest using GPS.
Got It!
Advertise Your App Here
 

iPhone Programming Tutorial - Intro to SOAP Web Services

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/URLLoadingSystem/Tasks/UsingNSURLConnection.html

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.

 

 

11 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?

Paulo Says:

November 4th, 2008 at 11:14 am

lovely background image you got there :D

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.

remei Says:

December 31st, 2008 at 6:44 am

Thnx! This was really helpful for me.

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?

Leave a Reply