2016-02-16 187 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]); 
        } 
}];