2011-11-24 64 views
2

我從我創建的站點下載XML文件,並且它在模擬器上正常工作;但是,它在電話上根本不起作用。它返回一個web異常錯誤和一個IO錯誤...以及來自HttpsCompleted事件的錯誤屬性,說錯誤遠程服務器返回錯誤。文件未找到。但這在我的模擬器上工作。XML下載在模擬器中工作,但不在電話上

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看起來像:

<request><Session><ID>1234-1234-1234-1234</ID><Title>Session Title</Title><Time>10:00AM-11:30AM</Time><Description>Some description.</Description></Session></request> 
+2

也許一個愚蠢的問題;但您的手機是否可以通過內置webbrowser訪問該文件? – Kolky

+0

@Kolky是啊我試過了,xml在瀏覽器中顯示正常 – jharr100

+0

是否可以通過PC上的fiddler路由實際設備? (你可以用一些設備)。例如像這樣的[iPhone例子](http://conceptdev.blogspot.com/2009/01/monitoring-iphone-web-traffic-with.html)?我有興趣知道'電話是否正確,它是文件未找到。 –

回答

0

因爲你冒險的NullReferenceException首先,這樣的代碼應該禁止:

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

然後,仿真器使用您的計算機的網絡連接,因此如果您的手機使用相同的連接,則問題與手機相關,與您的代碼無關。

相關問題