TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kannan AU
NA
57
24.4k
API Parallel call and how to make partial fail
Jun 8 2020 4:57 PM
Hi Team,
I have parallel call as showed below, at present if other API is failed for one AccountID, then complete call considering as fail. Could you please let me know how I can make the call better, Even if one AccountID is failed still I need to continue with final response for the success AccountID.
public
async Task<List<CreditCardSummary>> Process(Dictionary<
string
,
string
> permanentIds)
{
List<Task> tasks =
new
List<Task>();
List<CreditCardSummary> creditCardSummaryServiceList =
new
List<CreditCardSummary>();
foreach
(var permanentId
in
permanentIds)
{
CreditCardSummaryRequest request =
new
CreditCardSummaryRequest()
{
AccountID = permanentId.Key,
// "00001528830094858440"
AccountToken = permanentId.Value
//token
};
tasks.Add(ModelServiceProcessing(request).ContinueWith(
(TResult) => creditCardSummaryServiceList.Add(TResult.Result)));
}
await Task.WhenAll(tasks.ToArray());
return
creditCardSummaryServiceList;
}
public
async Task<CreditCardSummary> ModelServiceProcessing(CreditCardSummaryRequest request)
{
//deleted some code for constructing header
var restServiceResponse = await restClient.Post(ccStatusInfoUrl,request ,
true
, header);
// this is the code to make a call to other API
var restServiceResponseInformation = await restServiceResponse.Content.ReadAsStringAsync();
if
(!restServiceResponse.IsSuccessStatusCode)
{
throw
new
CallFailureException($
"Call has been failed"
);
}
context.LogQueue.AddDebugMessage($
"ICS CardSummary success for PId ending - {Common.GetLastFour(request.AccountID)}"
);
var response = Common.DeSerializeObject<CreditCardSummary>(restServiceResponseInformation,
false
);
return
response;
}
Reply
Answers (
0
)
Interop Excel : Copy sheet and put it in another workbook
ClosedXML and PageBreaks format