WP7从Web服务查询中设置公共字符串值 [英] WP7 Set public string value from web service query

查看:50
本文介绍了WP7从Web服务查询中设置公共字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Web服务中获取信息,然后在整个项目中使用该信息,但无法从Web服务查询中找出如何设置公共字符串.目前,我已经将ID硬编码到公共字符串中.如何将硬编码值替换为查询返回的值?

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";

推荐答案

您可以在id_DownloadStringCompleted()的末尾将myid的值分配给IDSetting.

You can assign the value of myid to IDSetting at the end of id_DownloadStringCompleted()

IDSetting = myid;

这篇关于WP7从Web服务查询中设置公共字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆