This is part of an ELC Tech Network

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

 

[ Javascript required to view QuickTime movie, please turn it on and refresh this page ]

-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.

Advertisement

-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.

 

This entry was posted in iPhone Programming Tutorials and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

68 Comments

  1. Posted October 21, 2009 at 8:30 am | Permalink

    It seems that the video isnt working? Is there something wrong on my end?

  2. Posted October 22, 2009 at 10:33 pm | Permalink

    I have created some wrapper classes and an objective C .NET dataset object class to easily incorporate passing datasets to your iphone app check it out!

    http://grabalife.com/2009/10/19/using-net-web-services-and-dataset-objects-in-your-iphone-app/

  3. John
    Posted October 27, 2009 at 4:30 pm | Permalink

    I’ve tried to put this example in a class to do a login via web service. I get my user id and password from the NSUserDefaults. I build the SOAP envelope and get my validated userId back in the web service…that works!!!

    In the parser didEndElement method I have the value I want (userId) in soapResults and am setting it like this:

    myUserId = [[NSString alloc] initWithString:soapResults];

    I have this as a property in the class .h file as:

    @property(nonatomic, retain) NSString *myUserId;

    I’d like to be able access that value by my view controller class that creates the instance to use the web service as:

    LoginWebService *loginWebService = [[LoginWebService alloc] init];

    [loginWebService logUserIn];

    Right now it returns void and I try to get the value from the myUserId property. This does not work.

    I also tried returning a string from the logUserIn method where the SOAP message is defined…again no luck.

    I apologize if I’m missing something obvious…I’m coming from the .Net world and trying to pick this stuff up.

    Please provide some help or an example of wrapping your code into a class that can return a value as a result of the web service having been contacted, parsed and return a string to the instantiating class (in my case a userId). Any help would be appreciated, my head is a bloody stump from beating it against my Mac Book.

    Thanks in advance.

  4. ashish
    Posted October 28, 2009 at 12:08 am | Permalink

    my webservice is returning array and it shows #[] only if I am returning string from service it is shown properly. what needs to be done to get response array in client from server.

  5. Shreedevi
    Posted November 2, 2009 at 2:42 am | Permalink

    Hi John, Please could you provide the code, so access to access a login web service.
    I am having a login web service, but still i did not get how to pass paramters like username and password to the web service.and also how to capture the results in the application.
    Please help.. I am very new to iphone application development.

  6. Posted November 3, 2009 at 12:35 am | Permalink

    Hello thank you for taking the time to
    create this tutorial it helped me alot.
    I am having one problem, getting an
    error when trying to access the webservice
    asmx file through the internet. When I try and
    access it via the internet I get an
    xml parsing error. When I right click
    the file and select view in browser it opens
    fine on the server. When I try and
    open the file on the server through
    port 8000 the port I am using for incoming
    internet connections I get the same error.
    What am I doing wrong?

  7. aaron
    Posted November 6, 2009 at 4:25 pm | Permalink

    Nice tutorial. Thanks.

    John,

    Maybe I’m misreading your post, but I don’t see where you are making the value of “myUserID” externally visible. What does your “logUserIn” method look like? Are you synthesizing the getter/setter for “myUserID?”

  8. Amit
    Posted November 25, 2009 at 5:24 am | Permalink

    Gr8 Tutorial
    Thanks !!!!!!!

    It is working gr8 for .asmx service BUT not working while dealing with WSDL web service.
    I am getting following error …

    Error Code: 407 Proxy Authentication Required. The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. (12209)

    Plz Help

  9. Posted November 29, 2009 at 2:13 pm | Permalink

    Excellent blog, i like it. I should just give up and take lessons from you

  10. Leo
    Posted December 8, 2009 at 9:40 pm | Permalink

    Thanks for the great tutorial.

    When i create my simple helloworld web service hosted by IIS on a local machine, my response from my IMAC is ZERO bytes, may I know what is the problem?

    Has it got to do with the hosting of the web service?
    I am able to see the operations page on Safari from the IMAC, hence connection should be fine.

    Thank you for any help.

  11. Bhramar
    Posted December 15, 2009 at 5:07 am | Permalink

    Gr8 Tutorial
    Thanks alot…

    Can i expect any clue or tutorial to connect database related Webservice which returns Datatable/Dataset.

    Thanks in Advance…

  12. Posted January 7, 2010 at 11:03 am | Permalink

    I used ur code pretty much exactly in my project,just with some minor modifications, i just want to know if i have to put a copyright notice u might have made before i submit the application?

  13. Aditya
    Posted January 12, 2010 at 1:40 pm | Permalink

    good tutorial…thanks!

  14. Gendarme
    Posted January 31, 2010 at 2:16 pm | Permalink

    Great entry point into WS communication from iPhone! Works for WSDLs without any problems! Thanks a lot!

  15. Heijtink
    Posted February 1, 2010 at 5:26 pm | Permalink

    Thank you for the great tutorial. I have one question though. In the example given you pass a string value ‘nameInput.Text’ to the NSString. However, how would one go about adding a boolean value to the NSString? I need to tell the Web Service whether I want the result back compressed or not. And I would like to set it to false.

  16. Posted February 16, 2010 at 9:55 am | Permalink

    Thank’s so much!

  17. Posted March 1, 2010 at 12:48 pm | Permalink

    I lately came across your blog and have been reading along. I thought I would leave my first remark. I don’t know what to say except that I have loved reading. Respectable blog. I will keep visiting this blog very often.

  18. Posted March 8, 2010 at 8:57 pm | Permalink

    Hey, Good evening it´s just i do totally dig Your blog, I wuold enjoy to blog a teaser on your incredible wordpress blog on my silly Apple iPad Website http://www.soulcast.com/ipadnewssvcip/rss would you grant me permission? XoX, Hortensia Batterton

4 Trackbacks

  1. [...] 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 [...]

  2. By ParaSite | Uploading on May 23, 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 [...]

  3. By Web Services Tutorial on July 18, 2009 at 6:48 am

    [...] iCodeBlog » Blog Archive » iPhone Programming Tutorial – Intro to … [...]

  4. [...] the data on air, i totally got insane . If you want to know how bad is, try to visit these site : iPhone Programming Tutorial : Intro To Soap Web Services (or Turkish version : iPhone ile Web Service [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">