I have this web service and it called the public api for accounting application like Xero. But for some reason, after each call, my page is frozen. It seems to be stuck in a deadlock? Here is my code:
[WebMethod(EnableSession = true)]
public async Task<string> syncToAccountingAppAsync(string serviceType)
{
if(serviceType == "ABC"){
//return await InsertXeroService(id, serviceType); //This doesn't work either.
List<Task<string>> tasks = new List<Task<string>>();
tasks.Add(InsertXeroService(serviceType));
var results = await Task.WhenAll(tasks);
return results[0];
}
}
And here is my InsertXeroService function
private async Task<string> InsertXeroService(string serviceType)
{
var invoice = new Xero.NetStandard.OAuth2.Model.Accounting.Invoice
{
......
};
var invoiceList = new List<Xero.NetStandard.OAuth2.Model.Accounting.Invoice>();
invoiceList.Add(invoice);
var invoices = new Invoices();
invoices._Invoices = invoiceList;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
var AccountingApi = new AccountingApi();
var response = await AccountingApi.CreateInvoicesAsync(xeroken.AccessToken, tenantId, invoices);
return response._Invoices[0].UpdatedDateUTC.ToString();
}
The data was synced to the accounting application just fine. But it never returned the response. And my web application just hanged up until I closed and reopened it. Could someone explain if I did something wrong? Thanks