Calling web service and XML Parser from another class - iphone

I have an application in which I have to hit many web services in same class and from another classes also and I have to parse the data each time.I cant write the delegate methods for webservice hit and XML Parse everytime as its not a good programming practice. So I thought of maintaining common classes for 'webserviceHandler' and 'XMLParsingHandler' in which I will write delegate methods for web service and XMLParsing respectively.
Now the problem is how to make it happen to call these delegates each and everytime I hit the webservice from another classes..??
Code for this is more appreciable..
Thanks in advance..

Cocoa Programming for Mac OS X Chapter 28. Web Services using NSXMLDocument
There is also an example from ADC SeismicXML using NSXMLParser

Related

iPhone server-client application

I'm not sure this question is appropriate here but I hope I could get some help. What i'm looking to do is basically to make a server based iPhone application. I've got an ubuntu server ready to be used. I'm thinking of making a web service which my application then can use but I have virtually no experience in this field so i'm looking for some help to get pointed into the right direction, what language to write the web service in etc. It isn't required to be a web service but anything that make's the iPhone app depending on the server.
This little mission is simply for learning experience.
Probably PHP is what you will use to write the webservice. REST based services are the most popular, but it could be as simple as a form POST passing in parameters. The PHP script (no matter which way you write it), will then pass those parameters and any other needed info to a server method that either executes a SQL query (preferably using a stored procedure) or uses some other server resource. That data would then be output via the webservice as either XML or JSON (I personally like JSON better).
Check out Ray Wenderlich's tutorial on just this kind of thing:
When it comes time to handle the request in iOS, my personal choice is AFNetworking. It uses blocks instead of delegate methods and is blazing fast. I can hook you up with examples if needed.
Ok, First you need to learn how to write web services in PHP. Which will return you response in XML format. I personally prefer .PLIST format because it gets easier to parse on the iOS.
Once your web services are up and running. You need to use NSURLConnection and NSURLRequest to talk to your web services. Implementing the NSURLConnection Delegate methods correctly, you can download your XML response, maybe save it in a file on your Documents Directory.
Then once done downloading start parsing that response using NSXMLParser. implementing the delegates and what not, you can create your data structure the way you feel comfortable with manipulating it and store the parsed results in them and populate your View accordingly.

reusable web services code for iPhone

I am very new to iPhone development and previously was working with Java.
Currently I am using SOAP web services in my project and want to continue with the same.
But everytime i have to write the same code for all kinds of web services except for the parameters.
Can anyone guide me regarding how can i create a reusable code for web-services, so that i can use it as a static library or something for every project and then i wont need to write any code separately for each kind of web service?
I want to create a code which would be very generic and will be work for all kinds of web services irrespective of the number of parameters.
create the singleton class and method will be class methods then they will be globally used you can use them by doing a little modification in the code .
Create a seperate Webservices Manager Class (.h and.m) files where you have to write code for nsurlconnection and urlrequest creation in a method.
Also place all the NSURLConnection delegate methods(connection:didRecieveResponse: etc) in the same class to handle the response coming from server.
Create protocol methods to pass this nsdata response from the NSURLConnection delegate method(connection:didReceiveResponse:) to the appropriate classes. Implement the delegate method in those classes, get the response from this common nsurlconnection class.
Parse the response data.
So when you need to call a webservice, just make a call to the nsurlConnection creation method of the WebservicesManager class ( [webserviceManager connectTo:#""]) to actually initiate a webservice call.

iPhone Noob, needs suggestions on how to communicate with the internets via iOS

we were asked to develop an iphone app like the one in the figure.
The problem is: we have no experience in IOS development.
For the basic part I can handle the learning curve, but i need suggestions, best practices on the UIKit model and controls.
This is a newspaper app.
The accordion control shows/hides content based on categories retrieved by an ASP .NET CMS on which we have no control.
I can suggest to the CMS holder to develop a couple of web services (WCF) but i'm not sure how to interface iOS with MS technology.
Furthermore, i have the idea that simple aspx that returns XML/JSON data will be easier to call, and support, but slightly less secure.
So, suggestions? Tutorials?
If you like to use JSON and a very good HTTP-request-framework I have two links for you. Both sites contain various tutorials on how to use them.
json-framework
ASIHTTPRequest
Concerning the request and delegate stuff: For a start, I would skip the delegate part and use a synchronized HTTP request called in a thread (you'll see what that is on the second website). That makes the response handling a lot easier for the start. But I personally think, that using an asynchronous request is not a must. It's just nicer, if the architecture allows it. In my application, it wasn't realizable without lots of code overhead.
You want to output an XML feed in "plist" format (look it up, its simple theres lots of info on it).
Then you can do:
NSArray *plistContents = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:#"http://theinternet.com/pathToMyPlist.asp"]];
That will get all the output into an array.
Some other resources you may find interesting/useful include NSURLRequest and NSURLConnection. For the latter you will have to learn about delegate methods and such - its complicated, but its incredibly useful information.
We did several applications here using XML parsing like what you're suggesting at the end of your question. If you are concerned about security, you can implement handshaking or other security measures over that.
EDIT: XML parsing done using NSURLConnection to gather the content and NSXMLParser/NSXMLParserDelegate to do the actual parsing.
EDIT2: There is an official sample, called SeismicXML from Apple. It should get you started with iPhone XML parsing and data downloading.

consuming a .net web service and nsoperation

I am writing an ipad app that's going to list data, including images, from a WS.
I am going to consume a web service written in .net (.asmx). I looked at 2 examples,
the seismicxml that uses NSOperation and uses an xml feed.
another awesome example from Wei-Meng Lee that does not use NSOperation but shows how to make the soap envelope and uses an asmx service.
My question: is it better to use NSOperation and threading?
Or should I just forget about it and go with the simple implementation?
Plz help me, I am confused!
Thanks,
Simone
The SeismicXML and the LazyTables are good examples that show how to load images from a web service in a UITableView using NSOperation and xmlParser. But the NSURLConnection request is called outside the NSOperation, so I had to modify it a little to suit my purposes. Another good example that I found is the LinkedImageFetcher which shows how to fetch images from a website, and includes NSURLConnection request inside an NSOperation.

How to use webservice in iphone objective c?

I need great video tutorial for using webservices in iphone objective c.My requirment is already values are in webservice, so just i want to access the webservice and validate username and password and return back to true or false get value display on the iphone.
If anybody have idea about tutorial please help me out..
The by far easiest way to consume a web service on an iPhone is to use Hessian. Implement the server in Java using the official Hessian distribution, or in .NET using HessianC#.
Let us assume you have defined the following interface for your web service, and implemented it as a HessianServlet (Just replace a HttpServlet):
public interface MyService {
public String doWithStuff(String action, Object stuff);
}
It is just as easy on .NET.
On the client side use HessianKit, where you create proxies to the web service, and then use them just as if they where local object. First you must conbert the Java interface above to an Objective-C protocol.
#protocol MySertvice
-(NSString)do:(NSString*)action withStuff:(id)stuff;
#end
Then use it as a proxy, just as if it was a local object:
id<MyService> proxy = [CWHessianConnection proxyWithURL:serviceURL
protocol:#protocol(MyService)];
NSLog(#"%#", [proxy do:#"Something" withStuff:arguments]);
Hessian in a binary web service protocol, meaning allot smaller payloads, which is good on a slow GSM connection. Hessian is also much easier to encode and decode, compared to XML and JSON, meaning your app can make calls and receive responses using less CPU, and memory for temporary objects.
iPhone on Rails is
an Objective-C port of Ruby on Rails'
ActiveResource.
but it can be used as a wrapper to access any RESTful webservice. ObjC classes and objects correspond to ActiveRecord classes and objects (which correspond to data base tables and rows).
There's an introductory screencast over here.