sagarkothari
sagarkothari

Reputation: 24810

How to Fetch Data From a WebService in iPhone?

I have to develop an application which includes following things,

=> Make a request to the Web Service through an iPhone...

=> fetch Data from web service...

I have never used an web service to develop iPhone application.

But i know what is web service.

The example of web service is given below. a snapshot alt text

Upvotes: 2

Views: 11901

Answers (3)

Pradeep Reddy Kypa
Pradeep Reddy Kypa

Reputation: 4022

U can do it this way...

-(NSString* )createWebServiveRequest:(NSString *)urlLink{

NSURL *url = [NSURL URLWithString:urlLink];

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];

NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse: nil error: nil ];

NSString *responseString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

return responseString; }

call the above method with the nsstring containing url.....and capture it in the method call.

Upvotes: 0

Daniel
Daniel

Reputation: 22395

To retrieve data from the webservice you can use NSURLRequest or NSMutableURLRequest

...where you can use methods such as + sendSynchronousRequest:returningResponse:error: or sendAsynchronousRequest. If you are simply doing a get, you can retrieve your xml or json in a very easy way using [NSString s tringWithContentOfURL:url] this will read in the response into the string you assign it to.

Upvotes: 5

Matthew Belk
Matthew Belk

Reputation: 1924

I developed some REST services using ASP.NET MVC to return XML documents that were created using Apple's native plist schema. The iphone can very naturally parse plists into their native types. plist is a little verbose compared to JSON, but I don't think it's that much more payload overhead.

If you already have some SOAP web services, then you will have to build your own custom, domain-specific XML parser.

-MrB

Upvotes: 1

Related Questions