我正在尝试从Web服务中恢复信息,然后在整个项目中使用该信息,但无法弄清楚如何从Web服务查询中设置公共字符串。目前,我已经将id硬编码到公共字符串中。如何将硬编码值替换为查询返回的值?
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";
答案 0 :(得分:1)
您可以在id_DownloadStringCompleted()结束时将myid的值分配给IDSetting
IDSetting = myid;