2016-04-11 25 views
0

這是我的代碼:智能的方式不殺的WebService

for (FlightScopePlayerPlayer *player in self.selectedPlayers) { 
BaseballPlayer_GetBaseballProfileRequest *re = [[BaseballPlayer_GetBaseballProfileRequest alloc]initWithPlayerID:player.ID]; 
      [bseModel.myFlightScopeClient.baseballPlayerServiceClient GetBaseballProfile:re 
                      onCompleted:^(id response) { 
                       BaseballPlayer_GetBaseballProfileResponse *res = (BaseballPlayer_GetBaseballProfileResponse *)response; 
self.player = res.player; 
[self.baseballPlayerList addObject:self.player]; 
[DelegateHelper performProtocol:@protocol(LoadPlayersFromWSModelCallbackDelegate) 
                             withTarget:self.delegates 
                            withSelector:@selector(isResponseRedyToUseAfterGetProfile:) 
                            withArgument:self]; 

這種結構可以殺死我的webservice。什麼是更聰明的方式發送這個?這個想法是,在數組中是對象,我想發送請求給大家,但如果在數組中將1000個對象Webservice可以死,所以我的想法是發送請求時,前一個完成併發送委託在最後。

+0

你應該能夠發送一個請求到服務器與一個ID列表,並讓服務器發送1迴應......您目前的代碼可能洪泛網絡,而不是打破了網絡服務 – Wain

+0

這個網絡服務創建在輸入只能得到1個ID。我不能發送ID的e.x數組 – hds

回答

0

理想情況下,你會有不同的web服務。

假設您無法更改,您需要對請求進行排隊,以便在任何時候都不會過多,並且如果需要可以暫停處理。您可能還可以通過將失敗的請求重新添加到隊列末尾來重試失敗的請求。

NSOperationQueue適合於此。您可以使用NSBlockOperation來包含處理邏輯來調用Web服務。一定要設置maxConcurrentOperationCount一些值1和4

0

之間可以使用RQOperation

基本想法是存儲在陣列中的網絡API調用,那麼您可以在串行的方式執行。 (一旦完成,執行下一個)

它有很好的樣品。希望有所幫助。

沒有足夠的代表發表評論,因此回答。