connecting to webservice

Discussion in 'iOS Programming' started by McBgnr, Aug 14, 2009.

  1. McBgnr macrumors regular

    Joined:
    Apr 13, 2009
    #1
    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
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. McBgnr thread starter macrumors regular

    Joined:
    Apr 13, 2009
    #3
    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?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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...
     
  5. McBgnr thread starter macrumors regular

    Joined:
    Apr 13, 2009
    #5
    Oh ... my mistake... Will be more careful going forward regarding this. Thanks a bunch for correcting me.
     
  6. mayurnilwant macrumors newbie

    Joined:
    Jun 3, 2010
    #6
    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....
     
  7. sjames macrumors newbie

    Joined:
    Jun 6, 2010
    #7
    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];
    }
    
     

Share This Page