2
votes

I am downloading an XML file from a site I created and it works fine on the emulator; however, it doesn't work at all on the phone. It comes back with a web exception error and an IO error...and the error property from the HttpsCompleted event says error the remote server returned an error. File not Found. BUT this works on my emulator.

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        WebClient wc = new WebClient();
        wc.DownloadStringCompleted += HttpsCompleted;
        wc.DownloadStringAsync(new Uri("http://.../SessionInfo.xml"));

    }

    private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        XDocument doc = null;
        string results = null;

        if (e.Error == null)
        {
            XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
            List<XElement> xelem = xdoc.Root.Elements() as List<XElement>;

            results = e.Result;

            var sessions = from x in xdoc.Descendants("Session")
                           select new
                           {
                               ID = x.Descendants("ID").First().Value,
                               TITLE = x.Descendants("Title").First().Value,
                               TIME = x.Descendants("Time").First().Value,
                               DESCRIPTION = x.Descendants("Description").First().Value
                           };

            foreach (var wd in sessions)
            {
                sessionsList.Add(new Session(wd.ID, wd.TITLE, wd.TIME, wd.DESCRIPTION));
                Debug.WriteLine("Session ID is {0}, Title is {1}, Time is {2}", wd.ID, wd.TITLE, wd.TIME);
            }
        }

        SessionInfoList.ItemsSource = sessionsList;

XML Looks like:

<request><Session><ID>1234-1234-1234-1234</ID><Title>Session Title</Title><Time>10:00AM-11:30AM</Time><Description>Some description.</Description></Session></request>
1
Maybe a stupid question; but is your phone able to access the file from the build-in webbrowser? - Kolky
@Kolky yea i tried and the xml comes up fine in the browser - jharr100
is it possible to route the actual device through fiddler on your PC? (you can with some devices). For example like this iPhone example? I'd be interested in knowing if the 'phone is right, and it was File not Found. - Marc Gravell
@Marc Gravell going to try it... - jharr100
@MArcGravell try this if you want to run fiddler and observe traffic for WP7 blogs.msdn.com/b/fiddler/archive/2011/01/09/… - AwkwardCoder

1 Answers

0
votes

First, Code like this should be prohibited because you risk the NullReferenceException :

TITLE = x.Descendants("Title").First().Value

Then, emulator uses internet connection of your computer, so if you use the same connection with your phone the problem is related to your phone, not related to your code.