Communicating using httpclient

SamWhelanSamWhelan USMember
edited August 2014 in Xamarin.Android

Hi, I have been attempting to retrieve data from my OData Service (the result of which I can see by hitting the url directly). I have accomplished this with ease in a console application (Visual Studio).

After following various tutorials including the ones on the developer section of this site, I have yet to achieve a working solution.

I have also attempted to create a basic application to call for a simple http response, however, as soon as the program makes the call, the application hangs before becoming unresponsive and failing to hit any further breakpoints.

The result in the application output always ends with:
[Mono] DllImport attempting to load: '/system/lib/libc.so'. [Mono] DllImport loaded library '/system/lib/libc.so'. [Mono] DllImport searching in: '/system/lib/libc.so' ('/system/lib/libc.so'). [Mono] Searching for 'gettid'. [Mono] Probing 'gettid'. [Mono] Found as 'gettid'.

Here is the code:
http://pastebin.com/jrB1EjUA

Any ideas as to why this might be?

Posts

  • CheesebaronCheesebaron DKInsider, University mod

    Try adding .ConfigureAwait(false) to your Task. However it is really nasty to create something async just to call it synchronously...

  • SamWhelanSamWhelan USMember
    edited August 2014

    Thanks for the reply.
    I tried adding newTask.ConfigureAwait (false); after creating the task, but the application still freezes after the call is made.
    (This happens at the line
    return await hc.GetAsync (uri.ToString());)

    Here is a link to the modified code
    http://pastebin.com/9ZV8nsPK

  • CheesebaronCheesebaron DKInsider, University mod

    Add it to the GetAsync method as well.

  • SamWhelanSamWhelan USMember
    edited August 2014

    Sorry, which line am I supposed to add it in that case?
    edit:
    like this?

    'return await (hc.GetAsync (uri.ToString())).ConfigureAwait(false);'

    Thanks, got it working.

  • SamWhelanSamWhelan USMember

    Ok, so I got it working with the http request, so I tried to copy the methodology over to my OData test program.
    Would you mind having a look to see if you can spot anything obvious, as it still freezes when using OData as opposed to http.
    http://pastebin.com/vUQX7vVu

  • CheesebaronCheesebaron DKInsider, University mod

    It is in general bad practice to call async methods in constructors and in void methods. You should really avoid that.

    Stephen Cleary has some nice blog posts about Async OOP: http://blog.stephencleary.com/2013/01/async-oop-0-introduction.html read the posts, they are really informative.

Sign In or Register to comment.