Using Webservice in iOS

87 %
13 %
Information about Using Webservice in iOS

Published on March 10, 2014

Author: mahboobnur



This is a comprehensive slide on implementing web service in iOS . There are basic information on Web Service . There are steps of using web service in iOS. The presentation emphasized on XML Parsing .

Working with Web Service in iOS

Syed Mahboob Nur iOS Developer Blog: Fb Profile: Meetnar Profile:

Web Service A Web service is a method of communications between two electronic devices over the World Wide Web. It is a software function provided at a network address over the web with the service always on as in the concept of utility computing.

Several Types of Web Services WSDL • WSDL stands for Web Services Description Language • WSDL is an XML-based language for describing Web services. • WSDL is a W3C recommendation

Several Types of Web Services SOAP • SOAP stands for Simple Object Access Protocol • SOAP is an XML based protocol for accessing Web Services. • SOAP is based on XML • SOAP is a W3C recommendation

Several Types of Web Services UDDI • UDDI stands for Universal Description, Discovery and Integration • UDDI is a directory service where companies can search for Web services. • UDDI is described in WSDL • UDDI communicates via SOAP

Several Types of Web Services RDF • RDF stands for Resource Description Framework • RDF is a framework for describing resources on the web • RDF is written in XML • RDF is a W3C Recommendation

Advantage of Using Web Service in Mobile Application • • • • Minimize application size Minimize Code Size Easy to modify Reuse Application

Disadvantage of Using Web Service in Mobile Application • Internet Connection Required • Server have to be active 24/7

Working with Web Service in iOS (WSDL) WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information. The operations and messages are described abstractly, and then bound to a concrete network protocol and message format to define an endpoint. Related concrete endpoints are combined into abstract endpoints (services)

WSDL Example <xml> <types> <schema targetNamespace=" stockquote.xsd" xmlns=" XMLSchema"> <element name="TradePriceRequest"> <complexType> <all> <element name="tickerSymbol" type="string"/> </all> </complexType> </element> <element name="TradePrice"> <complexType> <all> <element name="price" type="float"/> </all> </complexType> </element> </schema> </types> </xml>

Steps of Implementing XML Service in IOS • Create a XML Parser file as NSObject type. • Write relevant code in the files. • Call the XML Parser class in a View Controller Class and load XML by url . • Parse the data and load in the containers or view components. Example : Table View, Picker View, Labels, Text Field etc.

Create a XML Parser file as NSObject type. #import <Foundation/Foundation.h> //#import "TeamViewController.h" #import "TeamInfo.h" @interface TeamParser : NSObject<NSXMLParserDelegate> { NSString *currentNodeImage; NSString *currentNodeName; NSXMLParser *parser; NSMutableArray *imageArray; NSMutableArray *nameArray; TeamInfo*teamInfo; } @property (nonatomic, retain) NSMutableArray *imageArray; @property (nonatomic, retain) NSMutableArray *nameArray; -(id) loadXMLByURL:(NSString *)urlString; @end

.m file implementation #import "TeamParser.h" @implementation TeamParser @synthesize imageArray; -(id) loadXMLByURL:(NSString *)urlString { imageArray= [[NSMutableArray alloc] init]; nameArray=[[NSMutableArray alloc]init]; NSURL *url = [NSURL URLWithString:urlString]; //parser = [[NSXMLParser alloc] initWithData:aData]; parser= [[NSXMLParser alloc] initWithContentsOfURL:url]; //parser = [[NSXMLParser alloc] initWithData:aData]; parser.delegate=self; [parser parse]; return self; }

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementname isEqualToString:@"team"]) { currentNodeImage=[[NSString alloc] init] ; currentNodeName=[[NSString alloc]init]; teamInfo=[[TeamInfo alloc]init]; } }

- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if ([elementname isEqualToString:@"logo"]) { teamInfo.teamLogo = currentNodeImage; //NSLog(@"image:%@",currentNodeImage); } if ([elementname isEqualToString:@"name"]) { teamInfo.teamName = currentNodeImage; //NSLog(@"name:%@",currentNodeImage); } if ([elementname isEqualToString:@"team"]) { [imageArray addObject:teamInfo]; [currentNodeImage release]; [currentNodeName release]; currentNodeImage = nil; currentNodeName=Nil; }

Call the XML Parser class in a View Controller Class and load XML by url . -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; teamImageParser = [[TeamParser alloc] loadXMLByURL:@" o.xml"]; imageNameArray=teamImageParser.imageArray; teamNameArray=teamImageParser.nameArray; for(int i=0;i<[imageNameArray count];i++) { NSLog(@"%@",[imageNameArray objectAtIndex:i]); } for(int i=0;i<[teamNameArray count];i++) { NSLog(@"%@",[teamNameArray objectAtIndex:i]);

Plot Parsed Data in the TableView - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[teamImageParser imageArray] count]; }

Plot Parsed Data in the TableView - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"TeamCustomCell"; TeamCustomCell *cell = (TeamCustomCell*)[teamTableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLabelObject = [[NSBundle mainBundle] loadNibNamed:@"TeamCustomCell" owner:self options:nil]; for (id currentObject in topLabelObject) { if ([currentObject isKindOfClass:[UITableViewCell class]]) { cell = (TeamCustomCell*) currentObject; break;

TeamInfo *teamInfo; teamInfo = [[teamImageParser imageArray] objectAtIndex:indexPath.row]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.headerTextLabel.text=teamInfo.teamName; NSLog(@"teamName: %@",teamInfo.teamName); imageQueueTeamLogo = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_async(imageQueueTeamLogo, ^ { UIImage *imageTVGuideLogo = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:[teamInfo teamLogo]]]]; dispatch_async(dispatch_get_main_queue(), ^ { cell.titleImageView.image = imageTVGuideLogo; [cell setNeedsLayout]; }); }); return cell; }

That’s all for today

#import presentations

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Getting Started · Consuming a RESTful Web Service from iOS

Consuming a RESTful Web Service from iOS. ... You will build an iOS client that consumes a Spring-based RESTful web service. ... using the "Single View ...
Read more

Using a web service in an iOS app - Stack Overflow

How might I go about using a web service in an iPhone app? For example, if I wanted to use a web service that you can use to convert a value into a ...
Read more

iOS Tutorial Part 1: Creating a Web service - TechRepublic

iOS Tutorial Part 1: Creating a Web service. ... we are going to begin to get into web services in an iOS environment. Most apps now use data from the web.
Read more

How to Write an iOS App That Uses a Web Service

A tutorial on how to write an iOS App that uses a web service. Comes with a companion tutorial showing you how to make the web service itself!
Read more

How To Write A Simple PHP/MySQL Web Service for an iOS App

A tutorial on how to write a simple PHP/MYSQL based web service that you can communicate with from an iOS app.
Read more

ios - Using asmx webservice in iPhone - Stack Overflow

i am using asmx webservice in my iPhone app , ... there is a function in webservice named : ... and the format to create request . iphone ios objective-c soap.
Read more

iOS Soap Webservice Calling and Parsing the Response ...

iOS Soap Webservice Calling and Parsing the Response. ... and general Webservice structure. Using the code ... I am new to Xcode and iOS, ...
Read more

Consuming .NET Web Services in an iOS Application

Web services allows to transfer the data between different platforms. There are scenarios where iOS application needs to send or receive data using an ...
Read more

iOS Quick Tip: Interacting with Web Services

At some point in your iOS development career, ... iOS Quick Tip: Interacting with Web Services ... I felt using them sped up development time and reduced ...
Read more

Creating a WCF Service with JSON Data and Using it on iOS

Creating a WCF Service with JSON data for use on iOS; Author: Melih Mucuk; Updated: 31 Mar 2013; Section: Mobile Development; Chapter: Mobile Development ...
Read more