Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Xamarin Forms App Calling Web API

Xamarin Forms App Calling Web API

Scheduled Pinned Locked Moved Mobile
jsoncsharpasp-netmobiledotnet
1 Posts 1 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I'm learning Xamaring Forms. I want to test connecting to a Web API. I have a an Asp.Net Framework Web API running and I can connect to to it. However, in my Xamarin Forms page, when I call it, the call to GetAsync never returns:

    public class MainPageViewModel : _ViewModelBase
    {
    private string url = "https://localhost:44340/api/Test/GetAll";
    public List Items { get; set; }
    public MainPageViewModel()
    {
    GetData();
    }
    private async Task GetData()
    {
    try
    {
    HttpClient client = new HttpClient();
    HttpResponseMessage response = await client.GetAsync(url); // <====== NEVER RETURNS

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();
                Items = JsonConvert.DeserializeObject\>(content);
            }
        }
        catch (Exception e)
        {
            throw;
        }
    }
    

    }

    I can paste the URL into a browser and see the JSON results. If the WebAPI is NOT running the GetAsync throws. Anyone have any thoughts on this?

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups