【问题标题】:How to call a Asynchronous SOAP web service?如何调用异步 SOAP Web 服务?
【发布时间】:2016-05-27 07:13:23
【问题描述】:

我想异步执行我的 SOAP Web 服务,因为我在同步调用时获取数据有些滞后。此外,当调用多个 Web 服务时,我能够在调用单个 Web 服务时获得结果(视图确实加载)或在(将出现视图)我无法获取数据。

谁能告诉我如何调用异步 SOAP webService:这是我的代码

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);

}

【问题讨论】:

  • 你可以使用 afnetwork 或 asihttp 或 nsurlrequest
  • vaibby Tanks 我会试试的。
  • 你要试试哪一个?
  • 我很复杂是他们解决这个问题的任何简单聪明的方法。
  • 尝试使用 nsurlrequest 作为启动器

标签: ios objective-c ios7 ios8 ios9


【解决方案1】:

您可以将 Web 服务调用包装在 GCD 异步块中,以使代码在后台异步运行

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

【讨论】:

  • 我要在此处包装哪些代码 1.soapStringMethod 或 2.my 响应方法 -(void)msgCount
  • 你的肥皂串方法,可以把你所有的代码放在块中,应该可以工作
【解决方案2】:
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]);
                    } 
}];

【讨论】:

    猜你喜欢
    • 2014-05-30
    • 1970-01-01
    • 2023-03-15
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多