Wednesday, August 15, 2012

XDocument.Parse problem

XDocument.Parse problem

Hello everyone,

I'm trying to parse an XDocument using WebClient; when I launch the page I receive this from the inner exception: "Security Error"

I can browse to the file from the web with no problems: http://www.theweatherproject.net/minmax.xml

 void readXML()          {                            WebClient client = new WebClient();             client.DownloadStringAsync(new Uri("http://www.theweatherproject.net/minmax.xml"));              client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);                        }            void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)          {              if (e.Error == null)              {                  XDocument document = XDocument.Parse(e.Result, LoadOptions.None);                    var MinMaxTemps = document.Descendants("Outdoor").Take(1)                             .Select(w => new                             {                                 MaxCelsius = w.Element("Max").Value,                                 MaxDate = w.Element("MaxDate").Value,                                 MaxTime = w.Element("MaxTime").Value,                                 MinCelsius = w.Element("Min").Value,                                 MinDate = w.Element("MinDate").Value,                                 MinTime = w.Element("MinTime").Value                             }).ToList();                    var MaxWind = document.Descendants("Wind")                      .Select(w => new                      {                          MaxMPH = w.Element("Max").Value,                          MaxDate = w.Element("MaxDate").Value,                          MaxTime = w.Element("MaxTime").Value                      }).ToList();                      recordTempGrid.DataContext = MinMaxTemps;                  recordWindGrid.DataContext = MaxWind;              }              else              {                  MessageBox.Show(e.Error.InnerException.Message, "Oops, something went wrong", MessageBoxButton.OK);              }          }



Answers & Comments...

Answer: 1

Do you have the clientaccesspolicy.xml at the root of the site hosting your service:

http://msdn.microsoft.com/en-us/library/cc197955(v=VS.95).aspx

 

by :

Answer: 2

I currently run the application from a development machine, the xml file resides on a home web server running IIS, do I add the clientaccesspolicy to my IIS root?

Many thanks

by :

Answer: 3

Yes

by :

Answer: 4

That worked great, thanks a lot

by :




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog