我正在使用 SOAP WebService 并使用 for 循环来循环我收到的帐户。
在每个循环中,我都会向 WebService 调用另一个请求,因此在发出请求时我需要在 for 循环中,去获取响应,然后继续循环。
下面是 for 循环的代码:
for (A2AWCAccount* account in accountList.Accounts) {
[_internalAccounts addObject:[[AccountDO alloc] initWithAccountName:[account localizedDescription] AccountNumber:account.Number Balance:[account.CurBal doubleValue] Currency:account.Curr]];
DataBank* dataBank = [DataBank getInstace];
A2AService* service = [A2AService service];
service.logging = YES;
A2AWCListCard* accountList = [A2AWCListCard alloc];
accountList.CustMnemonic = dataBank.customerId;
accountList.SessionID = dataBank.sessionId;
accountList.AccountNumber = account.Number;
accountList.Type = @"V";
// here i make the request
[service wrListCard:self listCard:accountList];
}
这是获取响应的方法的代码
- (void) onload:(id)value {
if ([value isKindOfClass:[A2AWCListCard class]]) {
A2AWCListCard* obj = (A2AWCListCard*) value;
if (obj.ErrorCode != 0) {
if (obj.ErrorCode == 109) {
[self handleSessionError];
return;
}else if (obj.ErrorCode == 116)
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Info", @"Info") message:[obj localizedError] delegate:self cancelButtonTitle:NSLocalizedString(@"Ok", @"Ok") otherButtonTitles:nil, nil];
alert.tag = 5;
[alert show];
return;
}
[self handleRequestError:[obj localizedError] closeView:YES];
return;
}
for (A2AWCCard* account in obj.Cards) {
[_cards addObject:[[CardDO alloc] initWithCardNumber:account.CardNo balance:[account.CurBal doubleValue] minimumPayment:account.CardAcc currencyCode:account.Status status:account.Curr cardName:[account localizedDescription] cardNo:account.Number]];
_totalBalance += [account.CurBal doubleValue];
}
[cardsPicker setNeedsDisplay];
[cardsPicker reloadAllComponents];
_servicesInitialized = YES;
}
}
这里发生的问题是循环使它调用 N 次取决于帐户的数量,例如,如果有 3 个帐户,它会发出 3 个请求,然后我等待 3 个响应,因此有时它会相互贡献,因为服务器有点慢.
有人帮忙吗??