Forum Cross Platform with Xamarin

HttpWebRequest.BeginGetResponse callback never called

Hi, I'm building app which need to consume some data from WebAPI in JSON format. I'm using HttpWebRequest for getting data (Project profile is PCL 4.0 - profile6). My code works as excepted on Android but on iOS (iPAD if this matter) I'm facing very odd bug. Code bellow is used for calling WebAPI service, line with string rawData is never reached on iOS when debugging. When I trace network traffic (using Charles) I see, that request has been made with http response 200. From my point of view it seems, that BeginGetResponse is called and than something wrong goes to threading and this task is not waiting to for complete.

    HttpWebRequest request = this.GetCommObject (path);
    request.Method = "GET";    
    request.BeginGetResponse ((IAsyncResult ar) => {                
                string rawData = string.Empty;
        }

I will be very glad if somebody can give me on right track.
Thanks in advance, Jindrich``

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Could you attach a .zip of a sample project that shows this behavior?

  • Thanks Adam, I have started separating code into project, which could be uploaded to this forum and now it's working, so its treading issue. In nonworking approach call is made in button handler, in working approach call is made in ViewDidLoad method. I will try to investigate this, but it seems that this is problem in my lack of iOS development knowledge.

    Thanks, Jindrich

Sign In or Register to comment.