0

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];
    NSLog(@"!, %@,%@",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!

titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133
cw9
  • 145
  • 1
  • 8
  • I hear about try asynchronous, is that a good direction? Cause I can't find any examples about calling soap function in that way – cw9 Aug 09 '11 at 19:59
  • Why not use Grand Central Dispatch? And, you're over-retaining `webService`...that's going to leak unless you already realise you'll need to `release` it twice and do so. – GarlicFries Aug 09 '11 at 20:22
  • Thanks @GarlicFries cause I was tring not to let the autorelease pool release my "webService"... – cw9 Aug 09 '11 at 21:09

1 Answers1

0

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

Community
  • 1
  • 1
Faizan S.
  • 8,634
  • 8
  • 34
  • 63