dalia.danny
New member
- Joined
- Mar 1, 2023
- Messages
- 3
- Programming Experience
- 1-3
Hello,
I wrote consume Web API as following,
This code work perfectly. Then, I'm calling it from another routine as following,
How to program, make it wait? Once the Web API response, then go
What happen now, my C# program not waiting Web API response
Please help
I wrote consume Web API as following,
C#:
public async Task<List<EditListFinalInv>> GetEditListFinalInvoices_Ifx(string Batch_Id,
string trans_ref)
{
HttpClient client = new HttpClient();
List<EditListFinalInv> _EditListInterimInv = new List<EditListFinalInv>();
string url = URLStr + "/GetEditListFinalInvoices_Ifx?Batch_Id=" + Batch_Id
+ "&&trans_ref=" + trans_ref + "";
client.BaseAddress = new Uri(url);
HttpResponseMessage response = await client.GetAsync("");
if (response.IsSuccessStatusCode)
{
string content = response.Content.ReadAsStringAsync().Result;
_EditListInterimInv = JsonConvert.DeserializeObject<List<EditListFinalInv>>(content);
}
return _EditListInterimInv;
}
This code work perfectly. Then, I'm calling it from another routine as following,
C#:
public async void ExecuteEditListBeforePostingInterimInvoice2(string JobBatchId, string UserId,
string paramData, string ReportName, string modelCurrentJob_Batch_Id, int JobId, string _reportFileName)
{
try
{
// this is Web API calling, need to wait get the result, then proceed to next line
var _objAPI = await objAPI.GetEditListFinalInvoices_Ifx(Send_Batch_Id, TransRefFrom);
// once get the web api response, then proceed
...
.....
.........
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
How to program, make it wait? Once the Web API response, then go
What happen now, my C# program not waiting Web API response
Please help