iOS call soap functions in thread
guys
I'm a new iOS developer, I'm having a problem when calling soap functions in new thread.
Here is more details:
I have a function calling soap web service:
WebService *webService = [[[WebService alloc]init]retain];
[webService getUser:self action:@selector(getUserHandler) userName: usnm encPassword: pswd];
This function is simply generated from sudzc.com(Great Website! Thanx!) simply calling this function I can get
<user><username>XXX</username><userStatus>XXX</userStatus><companyCode>XXX</companyCode><password>XXX</password></user>
back from webservice. and my getUserHandler will work perfectly.
but if I want to call the webservice in a thread like this:
[NSThread detachNewThreadSelector:@selector(myMethod) toTarget:self withObject:nil];
-(void)myMethod
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
N开发者_如何学GoSLog(@"!, %@,%@",usnm,pswd);
WebService *webService = [[[WebService alloc]init]retain];
[webService getUser:self action:@selector(getUserHandler) userName: usnm encPassword: pswd];
[pool drain];
}
I don't seem to get the returnxml, and it seems the getUserHandler never starts(I put a NSLog in the getUserHandler, but it won't print this time).
I got no idea why is this happening,
any hints are welcome!
Thanx!
I highly recommend you to look into the Sync-Async pattern as described in the tutorial here:
Sync-Async Pair Pattern – Easy concurrency on iOS
There is also a question focussing on the same issue:
Multiple async webservice requests NSURLConnection iOS
HTH
精彩评论