我试图从为我一直在努力的项目创建的Web服务访问数据。 我创建一个字符串创建NSURLConnection sendSynchronousRequest花费太多时间来响应
NSMutableString *sRequest = [[NSMutableString alloc] init];
[sRequest appendString:@"<soapenv:Envelope xmlns:soapenv=\"http:blah blah blah /messages\">"];
[sRequest appendString:@"<soapenv:Header/>"];
[sRequest appendString:@"<soapenv:Body>"];
[sRequest appendString:@"<mes:processActionRequest>"];
[sRequest appendString:@"<ProcessAction>"];
[sRequest appendString:@"</mes:processActionRequest>"];
[sRequest appendString:@"</soapenv:Body>"];
[sRequest appendString:@"</soapenv:Envelope>"];
然后我创建一个URL,并请求
NSURL *ServiceURL = [NSURL URLWithString:[[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"webservices" ofType:@"plist"]] valueForKey:@"EndPointURL"]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:ServiceURL];
[request addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL];
NSTimeInterval duration = [NSDate timeIntervalSinceReferenceDate] - start;
NSLog(@"Response Time%.4f",duration);
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
return responseData;
的问题是一个请求,即我在登录打印的响应时间总是为高于20秒不知何故。但是,当我使用eviware/SoapUI项目访问同一链接时,它会在一秒钟内执行,而且当黑莓项目中使用相同的链接时,它也可以顺利运行。我没有得到,我错在哪里。为什么iPhone的响应速度非常慢。请帮忙。 如果我听起来不太清楚,请告诉我。我会尽力详细说明。
我曾尝试使用异步API。它显示了相同的延迟响应。 – jason 2010-12-24 07:46:10