Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

McBgnr

macrumors regular
Original poster
Apr 13, 2009
144
0
Hello,

I want to write an application to connect to a webservice for iPhone. I am not sure how to start on this. What are the APIs that I would be needed for this purpose.

I am using SDK 3.0.

Cheers
McBgnr
 
Thanks for the input. I will check it out. Dont know how to pass the method name though!.

Meanwhile I was looking at the Webservices reference doc at apple documentation. It says to use WSMethodInvocationRef, but when I tried to use this in my project it gives compiler error. (undeclared). The coreservices framework is included in the project. Any other things that I may have missed out?
 
Thanks for the input. I will check it out. Dont know how to pass the method name though!.

Meanwhile I was looking at the Webservices reference doc at apple documentation. It says to use WSMethodInvocationRef, but when I tried to use this in my project it gives compiler error. (undeclared). The coreservices framework is included in the project. Any other things that I may have missed out?

You need to be very careful when reading the documentation: don't read the Mac OSX Core Foundation documents: read the iPhone ones. A search for WSMethodInvocationRef in the iPhone dev center returns nothing...
 
Oh ... my mistake... Will be more careful going forward regarding this. Thanks a bunch for correcting me.
 
expected declaration specifiers or '...' before 'CFXMLTreeRef'

I have included core services and Core Foundationn frameworks but it still doesn't work where in the correct frame work in my directory.... cn ne body gv me the path....
 
Here is some code which use the NSURLConnection to construct a request and process the response.

Code:
- (IBAction)fetchBooks:(id)sender
{
	NSLog(@"fetchBooks");
	//show user something is happending
	[progress startAnimation:nil];
	//get the value we are looking for
	NSString *input = [searchField stringValue];
	//escaping
	NSString *searchString = [input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
	NSLog(@"searchString = %@",searchString);
	//create the URL		
	NSString *urlString =[NSString stringWithFormat:
						  @"http://ecs.amazonaws.com/onca/xml?"
						  @"Service=AWSECommerceService&"
						  @"AWSAccessKeyId=%@&"
						  @"Operation=ItemSearch&"
						  @"SearchIndex=Books&"
						  @"Keywords=%@&"
						  @"Version=2007-07-16",
						  AWS_ID,searchString];
	
	NSLog(@"url - %@",urlString);
	
	NSString *signedURLString = [HMACSHA256 getSignedRequest:urlString withSecret:AWS_SECRET];
	NSLog(@"signed url %@",signedURLString);
	NSURL *url	= [NSURL URLWithString:signedURLString];

	
	
	NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
												  cachePolicy:NSURLRequestReturnCacheDataElseLoad
												 timeoutInterval:30];
	//fetch the response
	NSData *urlData;
	NSURLResponse *response;
	NSError *error;
	urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
	//check for errors in repsonse
	if(!urlData){
		NSAlert *alert = [NSAlert alertWithError:error];
		[alert runModal];
		return;
	}
	//parse the response
	[doc release];
	doc = [[NSXMLDocument alloc] initWithData:urlData options:0 error:&error];
	NSLog(@"doc = %@",doc);
	if(!doc){
		NSAlert *alert = [NSAlert alertWithError:error];
		[alert runModal];
		return;
	}
	[itemNodes release];
	itemNodes = [[doc nodesForXPath:@"ItemSearchResponse/Items/Item" error:&error] retain];
	if(!itemNodes){
		NSAlert *alert = [NSAlert alertWithError:error];
		[alert runModal];
		return;
	}
	//update interface
	[tableView reloadData];
	[progress stopAnimation:nil];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.