none
Microsoft.BCL.Async Library Windows Phone Class Library RRS feed

  • Question

  • I'm a bit puzzled and could do with some help. I have the following code for calling a webservice using the BCL.Async - UploadStringTaskAsync , the code below works fine when its in the xaml.cs class but when I move the code to a PhoneLibrary. it hangs on UploadStringTaskAsync line and never timeout or returns anything. Any thoughts what going wrong.

    xaml.cs

    var http = new WebClient();
    string postdata = "cmd=GWRLogin&data=%3cgip%3e%3cversion%3e1%3c%2fversion%3e%3cemail%3e???%40???????%3c%2femail%3e%3cpassword%3e3ec66b1?????156869af23318771f44aeb7f97780a88aa0e135c3f84%3c%2fpassword%3e%3c%2fgip%3e";
    http.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
    http.Headers[HttpRequestHeader.KeepAlive] = "true";
    http.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    http.Headers[HttpRequestHeader.ContentLength] = postdata.Length.ToString();
    var Token = await http.UploadStringTaskAsync("https://eon.?????.eu/???/???.php", "POST", postdata);

    Textblock.Text = Token;

    Dll and call

    private void Button_Click(object sender, RoutedEventArgs e)
    {
      Greenwave gw = new Greenwave();
      ResultBlock.Text = gw.Login().Result;
    }

    public class Greenwave
    {
      public async Task<string> Login()
      {
        var http = new WebClient();
        string postdata = "cmd=GWRLogin&data=%3cgip%3e%3cversion%3e1%3c%2fversion%3e%3cemail%3e???%40???????%3c%2femail%3e%3cpassword%3e3ec66b1?????156869af23318771f44aeb7f97780a88aa0e135c3f84%3c%2fpassword%3e%3c%2fgip%3e";
        http.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
        http.Headers[HttpRequestHeader.KeepAlive] = "true";
        http.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
        http.Headers[HttpRequestHeader.ContentLength] = postdata.Length.ToString();

        return await http.UploadStringTaskAsync("https://eon.?????.eu/???/???.php", "POST", postdata);
      }
    }

    Regards

    Kevin

    Saturday, July 20, 2013 7:24 AM

Answers

  • Solved it meself. I needed to add and async and an await to the call button click

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
      Greenwave gw = new Greenwave();
      ResultBlock.Text = await gw.Login();
    }

    the way nothing wrong with the BCL

    • Marked as answer by KevinTipps Saturday, July 27, 2013 1:54 PM
    Saturday, July 27, 2013 1:52 PM

All replies

  • Solved it meself. I needed to add and async and an await to the call button click

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
      Greenwave gw = new Greenwave();
      ResultBlock.Text = await gw.Login();
    }

    the way nothing wrong with the BCL

    • Marked as answer by KevinTipps Saturday, July 27, 2013 1:54 PM
    Saturday, July 27, 2013 1:52 PM
  • Hey Kevin, did you get anywhere with this project? Would you be open to sharing the source w/ me? I would love to create a WP app for these bulbs.
    Tuesday, October 21, 2014 5:47 PM
  • Oh, looks like it's proprietary based on the "eon" url and other information on Greenwave's website. Guess I'll have to go it alone!
    Tuesday, October 21, 2014 6:01 PM