I am trying to get live currency rate from this url: http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=GBP&ToCurrency=LTL
This is what I tried:
public void getRate(string howmuch, string from, string to)
{
int hmuch = int.Parse(howmuch);
string url = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=GBP&ToCurrency=LTL";
var xml = XDocument.Load(url);
var result = xml.Descendants("double");
btn.Content = result;
}
I get an error from XDocument.Load that I need to pass URI from filesystem, not URL from web. I didn't found correct way on the web to do this in windows phone, only with full C#. How to properly get that value between double tags?
Found a solution after ~4 hours:
This is how I call my function and convert result:
Note that method from which you call this function must be declared async as function itself, otherwise you can't use await operator.
Function:
Also don't forget to include needed headers:
You can try using
WebClient
to download XML content from internet :Then use
XDocument.Parse()
to load it toXDocument
object :Note that your XML has default namespace so it should be handled a bit differently (your current try won't work even if the
XDocument
was created successfully).