PDA

View Full Version : synchronous request for login using a WebService




pecorrea
Jan 29, 2009, 02:19 AM
Hi there,

I ask for your help here, i'm having a trouble (maybe it's conceptual too). I'm using some webservices to get data, but first there's a webservice to login, that returns a sessionId when successful. I've been using the code from icodeblog's tutorial about SOAP web services (this one (http://icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/)), but my problem is that i need this SOAP login thing to lock the application (like running on the main thread).

I've tried the performSelectorOnMainThread method, but my class doesn't recognize my selector ("[MainData login:]: unrecognized selector sent to instance 0x529f60'"). My code is something like this:

- (void) init {
// some code ...
lg = [[LoginWebServiceData alloc] init];
[self performSelectorOnMainThread:@selector(login:) withObject:nil waitUntilDone:YES];
// After login, we check what's on LoginWebServiceData's sessionId to see if there's a valid response
sessionId = lg.sessionId;
}

- (void)login {
[lg loginWithUsernameAndPassword:@"asdf" :@"asdf"];
}

Login is declared on the interface, so i don't know what's wrong ;( I think i can use the Synchronous request, but i think this is a better way to do this. Any ideas? :D



jnic
Jan 29, 2009, 05:16 AM
Your selector is login: but your method is just login (i.e. takes no arguments). You need to change your selector to match your method.

pecorrea
Jan 29, 2009, 01:19 PM
thanks jnic, now almost evrything is right. After testing my method to make synchronous SOAP, it doens't work :( looks like the Connection ([[NSURLConnection alloc] initWithRequest:theRequest delegate:self] ) runs on a different thread and i'll have to use "sendSynchronousRequest:returningResponse:error:", but i don't see a delegate there (the common request asks for a delegate). Does it have the same behavior as the asynchronous request? :o