C# 在某些Lumia 520(但不是我自己的)上进行httpClient.GetAsync()调用时,总是会发生TaskCanceledException

C# 在某些Lumia 520(但不是我自己的)上进行httpClient.GetAsync()调用时,总是会发生TaskCanceledException,c#,exception,windows-phone-8,httpclient,asynchttpclient,C#,Exception,Windows Phone 8,Httpclient,Asynchttpclient,我有一个通过web服务请求天气的方法。这在我的Lumia 520(在Windows Phone 8上)上运行得非常好,但是Lumia 520(也运行Windows Phone 8)上的一些用户报告说它从来都不起作用。我在beta版上得到了一个,使beta版输出成为异常,我被告知总是发生TaskCanceledException异常。这是该方法的代码: public async Task<string> getWeatherForCurrentLocation( bool isViaS

我有一个通过web服务请求天气的方法。这在我的Lumia 520(在Windows Phone 8上)上运行得非常好,但是Lumia 520(也运行Windows Phone 8)上的一些用户报告说它从来都不起作用。我在beta版上得到了一个,使beta版输出成为异常,我被告知总是发生TaskCanceledException异常。这是该方法的代码:

public async Task<string> getWeatherForCurrentLocation( bool isViaSettings = true )
{
    try
    {
    // Base url is to the web service with the API key and longitude/latitude provided.
    var baseURL = string.Format(URL_FULL_WEATHER, APIKEY, this.Locations[0].Latitude, this.Locations[0].Longitude);

    // Create an HttpClient instance
    var httpClient = new HttpClient();

    try
    {
        httpClient.Timeout = TimeSpan.FromSeconds(20);

        // Send a request asynchronously continue when complete
        HttpResponseMessage response = await httpClient.GetAsync(baseURL);

        // Check that response was successful or throw exception
        response.EnsureSuccessStatusCode();

        // Read response asynchronously
        string responseString = await response.Content.ReadAsStringAsync();

        // Deserialise response into a new ResponseCity object
        try
        {
            Location = JsonConvert.DeserializeObject<ResponseCity>(responseString);


            // rest of code
        }
        catch (Exception e)
        {
            return "fail";
        }
    }
    catch (TaskCanceledException t)
    {
        return "fail";
    }
}
catch (HttpRequestException e)
{
    return "fail";
}

return "success";
}
公共异步任务getWeatherForCurrentLocation(bool-isViaSettings=true)
{
尝试
{
//基本url指向提供了API键和经度/纬度的web服务。
var baseURL=string.Format(URL\u FULL\u WEATHER,APIKEY,this.Locations[0]。纬度,this.Locations[0]。经度);
//创建一个HttpClient实例
var httpClient=新的httpClient();
尝试
{
httpClient.Timeout=TimeSpan.FromSeconds(20);
//异步发送请求完成后继续
HttpResponseMessage response=等待httpClient.GetAsync(baseURL);
//检查响应是否成功或引发异常
response.EnsureSuccessStatusCode();
//异步读取响应
string responseString=wait response.Content.ReadAsStringAsync();
//将响应反序列化为新的ResponseCity对象
尝试
{
Location=JsonConvert.DeserializeObject(responseString);
//代码的其余部分
}
捕获(例外e)
{
返回“失败”;
}
}
捕获(任务取消异常t)
{
返回“失败”;
}
}
捕获(HttpRequestException e)
{
返回“失败”;
}
返回“成功”;
}
我已经设置了一个超时,以确保如果天气没有在20秒内成功返回,就会出现错误提示

有人知道为什么会这样吗

任何指导都将不胜感激

更新:


我在测试版上遇到了一个有问题的Lumia 520用户,我可以确认问题是url为他返回了404。这是一个“https”url。即使他试图通过IE打开链接,也没有显示任何内容。值得重复的是,这个URL确实有效。服务器不是我自己的;这是天气预报

异常发生在哪里?将调试器设置为在所有异常情况下中断。TaskCanceledException是被捕获的异常。如果您的意思是在哪一行发生异常,我还不能说,因为我目前没有访问手机进行调试,很遗憾,几周内都不会。发生异常需要多长时间?该URL是可访问的吗?该URL是100%可访问的,在我的1020上运行完全正常。在10秒之前超时,因此将其增加到20秒,并且仍然超时。