我試圖從爲我一直在努力的項目創建的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