Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Getting 'A task was canceled' after a few requests to the ASP.NET Web API

$
0
0

So, I'm building a Xamarin.Forms app and I made a little helper function for my requests to my Web API
public async static Task MakeGetRequest(string parameters, string url = null, bool hasISBN = false)
{
if(Bearer == null)
{
//bearer = await GetAuthToken();
}
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Bearer);

            var response = await client.GetAsync(string.Format("{0}/{1}", string.IsNullOrEmpty(url) ? baseUrl : url, parameters));

            var responseString = await response.Content.ReadAsStringAsync();

            return JsonConvert.DeserializeObject<ResponseType>(responseString);
        }
    }

All the calls to the API are awaited, and I'm making the calls using the IP, not to localhost.
But after a few requests, I'm starting to get the error "A task was canceled" on API calls.
If I deploy the API to Azure and make the calls there I'm not getting that error. Happens on UWP, Android and iOS.

Has anyone else encountered a similar problem?
Thanks


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>