iOS在线程中调用soap函数
伙计们,
我是一名新的 iOS 开发人员,我在新线程中调用肥皂函数时遇到问题。
这里有更多细节:
我有一个调用肥皂网络服务的函数:
WebService *webService = [[[WebService alloc]init]retain];
[webService getUser:self action:@selector(getUserHandler) userName: usnm encPassword: pswd];
这个函数是从 sudzc.com 简单生成的(很棒的网站!谢谢!) 只需调用这个函数我就可以
<user><username>XXX</username><userStatus>XXX</userStatus><companyCode>XXX</companyCode><password>XXX</password></user>
从网络服务中返回。我的 getUserHandler 将完美工作。
但如果我想在这样的线程中调用Web服务:
[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];
}
我似乎没有得到returnxml,而且getUserHandler似乎永远不会启动(我在getUserHandler中放置了一个NSLog,但这次不会打印)。
我不知道为什么会发生这种情况,
欢迎任何提示!
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我强烈建议您研究同步异步模式,如教程中所述:
同步异步配对模式 – iOS 上的轻松并发
还有一个问题集中在同一问题上:
多个异步 Web 服务请求 NSURLConnection iOS
HTH
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