Deadlock

chrisjngerchrisjnger USMember
edited June 2017 in Xamarin.Android

Hi all,

i am trying to develop my first Xamarin App....

i have two classes for webservices:
RestClient: which makes the request and get the json String
Helper Class: whick should get the Json String and deserialized it to the Object Type.

I know that the "Wait" Method is not the best option, but i have tried so many different suggested versions but it doesn't work.

code of my RestClient Class:

class RestClient
{

    public static string base_url = @"our Restservice address";
  //  public string completeUrl { get; set; }


    HttpClient client;



    public RestClient()
    {
        client = new HttpClient();
        client.BaseAddress  = new Uri(base_url);
        //client.MaxResponseContentBufferSize = 256000;

    }



      public async Task<String> GetData(string endpoint)
        {
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


        HttpResponseMessage response = await client.GetAsync(endpoint);
        if (response.IsSuccessStatusCode)
        {
            string result = await response.Content.ReadAsStringAsync();
            return result;
        }
        else
        {
            return null;
        }

    }

Code of my Helper Class

public SupplierHelper()
{

    }
    public async Task<Suppliers> getData()
    {


        RestClient restClient = new RestClient();

        string result =  await restClient.GetData("suppliers/13");
        return JsonConvert.DeserializeObject<Suppliers>(result);

    }

Code of my VievModelClass

public class AccountViewModel : BaseViewModel
{

    public static SupplierHelper supHelper;
    public static Suppliers sup;
    public string Name { set; get; }
    public string Address { set; get; }

    public AccountViewModel()
    {



   loadSupplier().Wait();



    }

   public  async Task loadSupplier()
    {

        supHelper = new SupplierHelper();
        sup =    await supHelper.getData();



    }
}

}

Sign In or Register to comment.