Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8459507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:20:58+00:00 2026-06-10T13:20:58+00:00

I’m trying to develop a simple WP7 app that queries a REST feed which

  • 0

I’m trying to develop a simple WP7 app that queries a REST feed which produces a XML file. Depending on the query, the feed can generate many different XML files, but I am having problems with the most basic one.

The XML I am trying to display in a ListBox looks like;

<subsonic-response status="ok" version="1.1.1">
</subsonic-response>

or

<subsonic-response status="ok" version="1.1.1">
<license valid="true" email="foo@bar.com" key="ABC123DEF" date="2009-09-03T14:46:43"/>
</subsonic-response>

I’ve tried following several examples from MSDN and other source but I can’t seem to wrap my head around it. The URL that I’m using works because it displays the correct information when entered into a browser, but for some reason isn’t displayed in the ListBox.

Here is the code I am currently using;

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;

namespace RESTTest
{
public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    string requestString =
    "http://WEBSITE/rest/{0}.view?u=USERNAME&p=PASSWORD&v=1.8.0&c=RestTest";
    string UriNoAppId =
    "http://WEBSITE/rest/{0}.view?u=USERNAME&p=PASSWORD&v=1.8.0&c=RestTest";
    public MainPage()
    {
        InitializeComponent();
        List<string> searchTopics = new List<string>() { "ping", "getLicense" };
        comboBox1.DataContext = searchTopics;
        comboBox1.SelectedIndex = 0;
        // Create the WebClient and associate a handler with the OpenReadCompleted event.
        wc = new WebClient();
        wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
    }
    // Call the topic service at the Bing search site.
    WebClient wc;
    private void CallToWebService()
    {
        // Call the OpenReadAsyc to make a get request, passing the url with the selected search string.
        wc.OpenReadAsync(new Uri(String.Format(requestString, comboBox1.SelectedItem.ToString())));
    }
    void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        XElement resultXml;
        // You should always check to see if an error occurred. In this case, the application
        // simply returns.
        if (e.Error != null)
        {
            return;
        }
        else
        {
            XNamespace web = "http://subsonic.org/restapi";
            try
            {
                resultXml = XElement.Load(e.Result);
                // Search for the WebResult node and create a SearchResults object for each one.
                var searchResults =
                from result in resultXml.Descendants(web + "WebResult")
                select new SearchResult
                {
                    // Get the Title, Description and Url values.
                    Title = result.Element(web + "version").Value,
                    Url = result.Element(web + "status").Value
                };
                // Set the data context for the listbox to the results.
                listBox1.DataContext = searchResults;
                textBox1.DataContext = searchResults;
            }
            catch (System.Xml.XmlException ex)
            {
                textBlock2.Text = ex.Message;
            }
        }
    }
    private void button1_Click(object sender, RoutedEventArgs e)
    {
        CallToWebService();
    }
    // Update the textblock as the combo box selection changes.
    private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        uriTextBlock.DataContext = string.Format(UriNoAppId, e.AddedItems[0]);
    }

}
// Simple class to hold the search results.
public class SearchResult
{
    public string Title { get; set; }
    public string Url { get; set; }
}
}

XAML

<phone:PhoneApplicationPage 
x:Class="RESTTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="False">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.Resources>
        <Style x:Key="ComboBoxItemStyle" TargetType="ComboBoxItem" >
            <Setter Property="Foreground" Value="Black"/>
            <Setter Property="Background" Value="LightGray"/>
        </Style>
        <Style x:Key="ComboBoxStyle" TargetType="ComboBox" >
            <Setter Property="Foreground" Value="Black"/>
            <Setter Property="Background" Value="Gray"/>
        </Style>
    </Grid.Resources>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="REST CLIENT"
                   Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="Subsonic"
                   Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"
                   Height="99" Width="453" />
    </StackPanel>
    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Margin="12,139,12,0" Grid.RowSpan="2">
        <Button Content="Search!" Height="89" HorizontalAlignment="Left"
                Margin="264,140,0,0" Name="button1"
                VerticalAlignment="Top" Width="189" Click="button1_Click" />
        <ComboBox Height="50" Style="{StaticResource ComboBoxStyle}"
                  HorizontalAlignment="Left" Margin="6,159" Name="comboBox1"
                  ItemContainerStyle="{StaticResource ComboBoxItemStyle}"
                  VerticalAlignment="Top" Width="235" ItemsSource="{Binding}"
                  SelectionChanged="comboBox1_SelectionChanged" />
        <TextBlock Height="36" HorizontalAlignment="Left" Margin="12,120"
                   Name="textBlock2" Text="Search Topic:" VerticalAlignment="Top" width="121" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="12,1,0,0"
                   Name="textBlock3"
                   Text="URI:" VerticalAlignment="Top" />
        <TextBlock Height="86" HorizontalAlignment="Left" Margin="6,28"
                   Name="uriTextBlock" TextWrapping="Wrap" Text="{Binding}"
                   VerticalAlignment="Top" Width="447" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="12,242,0,0"
                   Name="textBlock5"
                   Text="Results:" VerticalAlignment="Top" />
        <ListBox Height="169" HorizontalAlignment="Left" Margin="6,271,0,0" Name="listBox1"
                 VerticalAlignment="Top" Width="444" ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="{StaticResource PhoneForegroundBrush}" Width="418"
                            BorderThickness="2" Margin="2">
                        <StackPanel>
                            <TextBlock Text="{Binding Path=Title}" TextWrapping="Wrap" />
                            <TextBlock Text="{Binding Path=Url}" TextWrapping="Wrap"/>
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <TextBox Height="209" HorizontalAlignment="Left" Margin="6,446,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="444" IsEnabled="True" IsReadOnly="True" />
    </Grid>
</Grid>
</phone:PhoneApplicationPage>

The code is currently designed so you can choose to display either one of the example XML files, but nothing is displayed in the Listbox at all.

Any advice would be appreciated. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:21:00+00:00Added an answer on June 10, 2026 at 1:21 pm

    See if the following helps:

    string fakeXML = "<subsonic-response status='ok' version='1.1.1'>" +
                     "<license valid='true' email='foo@bar.com' " +
                     "  key='ABC123DEF' date='2009-09-03T14:46:43'/>" +
                     "</subsonic-response>";
    XDocument doc = XDocument.Parse(fakeXML);
    
    var searchResults = from xe in doc.Elements("subsonic-response")
                        select new SearchResult
                        {
                          Title = xe.Attribute("version").Value,
                          Url = xe.Attribute("status").Value
                        };
    listBox1.DataContext = searchResults;
    textBox1.DataContext = searchResults;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm trying to select an H1 element which is the second-child in its group
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.