Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 7 使用WP7的Web服务_Windows Phone 7 - Fatal编程技术网

Windows phone 7 使用WP7的Web服务

Windows phone 7 使用WP7的Web服务,windows-phone-7,Windows Phone 7,我非常感谢您对我上一个问题的帮助,我想知道如何使用web服务从URI读取数据(假设它是相同的数据)。 以下是url链接: 我尝试使用此代码,但没有成功: public MainPage() { InitializeComponent(); WebClient wc = new WebClient(); wc.DownloadStringCompleted += new DownloadStringCompletedEventHa

我非常感谢您对我上一个问题的帮助,我想知道如何使用web服务从URI读取数据(假设它是相同的数据)。 以下是url链接: 我尝试使用此代码,但没有成功:

 public MainPage()
        {
        InitializeComponent();

        WebClient wc = new WebClient();
        wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(download_string_complete);
        wc.DownloadStringAsync(new Uri("http://www.google.com/ig/api?weather=hammamet", UriKind.Absolute));
        }

    public void download_string_complete(object sender, DownloadStringCompletedEventArgs e)
        {


       if (e.Error == null)
            {
            ListBoxItem areaItem = null;
            StringReader stream = new StringReader(e.Result);
            XmlReader reader = XmlReader.Create(stream);

            string day = String.Empty;
            string low = String.Empty;
            string high = String.Empty;
            string condition = String.Empty;

            while (reader.Read())
                {
                if (reader.NodeType == XmlNodeType.Element)
                    {
                    if (reader.Name=="forecast_conditions")
                        {
                    WeatherElement welement = new WeatherElement();
                    switch (reader.Name)
                        {
                        case ("day_of_week"):
                                {
                                day = reader.ReadElementContentAsString();
                                areaItem = new ListBoxItem();
                                areaItem.Content = day;
                                friendsBox.Items.Add(day);
                                } break;

                        case ("low"):
                                {
                                low = reader.ReadElementContentAsString();
                                areaItem = new ListBoxItem();
                                areaItem.Content = low;
                                friendsBox.Items.Add(low);
                                } break;

                        case ("high"):
                                {
                                high = reader.ReadElementContentAsString();
                                areaItem = new ListBoxItem();
                                areaItem.Content = high;
                                friendsBox.Items.Add(high);
                                } break;

                        case ("condition"):
                                {
                                condition = reader.ReadElementContentAsString();
                                areaItem = new ListBoxItem();
                                areaItem.Content = condition;
                                friendsBox.Items.Add(condition);
                                } break;
                        }

                    }
                }
            }
        }
    }

你能解释一下“它没用”吗?它怎么没用的?发生了什么事?有错误吗?如果是,什么?哪一行代码导致了这些问题?当我运行应用程序时,它会显示一个空屏幕(它没有读取数据),你做了什么来调试它?实际上我找到了另一种方法!谁能帮我展示一下这个图像!!因为只有它的url才会显示
  void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            StringReader stream = new StringReader(e.Result);
            XmlReader reader = XmlReader.Create(stream);

            string Day = String.Empty;
            string Low = String.Empty;
            string High = String.Empty;
            string ImageUri = String.Empty;
            string Condition = String.Empty;

            reader.MoveToContent();

            while (reader.Read())
            {
                switch (reader.Name)
                {
                    case ("day_of_week"):
                        {
                            listBox1.Items.Add(new ListBoxItem()
                              {
                                  Content = reader.GetAttribute("data")
                              });
                            Day = Content.ToString();
                        } break;
                    case ("low"):
                        {
                            listBox1.Items.Add(new ListBoxItem()
                            {
                                Content = reader.GetAttribute("data")
                            });
                            Low = Content.ToString();
                        } break;
                    case ("high"):
                        {
                            listBox1.Items.Add(new ListBoxItem()
                            {
                                Content = reader.GetAttribute("data")
                            });
                            High = Content.ToString();
                        } break;
                    case ("icon"):
                        {
                            listBox1.Items.Add(new ListBoxItem()
                            {
                                Content =  reader.GetAttribute("data")
                            });
                            Image wkpinImage = new Image();
                            wkpinImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("http://www.google.com" + Content, UriKind.Absolute));
                            wkpinImage.Opacity = 0.8;
                            wkpinImage.Stretch = System.Windows.Media.Stretch.None;
                        } break;

                    case ("condition"):
                        {
                            listBox1.Items.Add(new ListBoxItem()
                            {
                                Content = reader.GetAttribute("data")
                            });
                            Condition = Content.ToString();
                        } break;
                    case("weather"):
                    break;  
                }
            }
        reader.Close(); 
            }
        }