2016-02-16 190 views
0

我想要异步执行我的SOAP的Web服务,因为我得到了在获取数据,同时呼吁synchronously.Also我能得到调用时,多个Web服务被称为在一个单一的Web服务时产生一定的滞后性(图做负载)或在(查看会出现)我无法获得的数据。如何调用异步SOAP Web服务?

谁能告诉如何调用一个异步SOAP web服务:这是我的代码

cws = [[CustomWebService alloc]init]; 

    NSString *soapMessage = [NSString stringWithFormat:@"my soap string"]; 


    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(msgCount) name:@"my response name" object:nil]; 
    NSDictionary *Details=[[NSDictionary alloc]initWithObjectsAndKeys:nil]; 
    [cws getSoapAction:@".........." andNameSpace:@"" andDetails:Details andUrlIs:[AppDelegate URLSource] andSoapMessage:soapMessage ]; 
    [cws getPageName:@"my response name"]; 
    NSLog(@"SOAP MESSAGE IS %@",soapMessage); 

而且我在这里得到了响应:

-(void)msgCount 
{ 
[[NSNotificationCenter defaultCenter]removeObserver:self]; 
NSMutableDictionary *diict=[[NSMutableDictionary alloc]initWithDictionary:[cws msgCount]]; 
NSLog(@"the response is %@",diict); 

} 
+0

ü可以使用afnetwork或asihttp或的NSURLRequest – vaibby

+0

vaibby坦克我会尝试。 – Arun

+0

哪一个你想要? – vaibby

回答

0

你可以在一个GCD异步包装您的Web服务调用块使代码在后台异步运行

dispatch_async(dispatch_get_main_queue(), ^{ 
     //code that should run asynchronously 
}); 
+0

我想要的代码,在这里包1 soapStringMethod或2.my应对方法 - (无效)MSGCOUNT – Arun

+0

你的肥皂字符串的方法,只需把所有的代码块中,应该努力 – Fonix

+0

感谢Fonik我会尝试你的选择。 – Arun

0
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"UR URL"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; 
[request setHTTPMethod:@"POST"]; 
NSString *postString = @"UR KEY1=UR VALUE1"; //for single variable 

//OR for Multiple 

[request setValue:@"UR VALUE1" forKey:@"UR KEY1"]; 
[request setValue:@"UR VALUE2" forKey:@"UR KEY2"]; 

[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; 
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
{ 
    if (error) { 
         NSLog(@"Error,%@", [error localizedDescription]); 
        } else { 
         NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]); 
        } 
}];