I’m trying to bring back information from a web service and then use that piece of information throughout my project but cannot figure out how to set a public string from a web service query. At the moment, i’ve hard coded the id into the public string. How do I replace the hard coded value with the value returned by query?
public MainPage()
{
WebClient id = new WebClient();
id.Credentials = new NetworkCredential(UsernameSetting, PasswordSetting);
id.DownloadStringCompleted += new DownloadStringCompletedEventHandler(id_DownloadStringCompleted);
id.DownloadStringAsync(new Uri("https://web-service-address/"));
}
void id_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
XDocument xDocument = XDocument.Parse(e.Result);
var myid = xDocument.Descendants("service").First();
}
public string IDSetting = "1234567";
You can assign the value of myid to IDSetting at the end of id_DownloadStringCompleted()