Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Read xml stream from url
8 replies. Latest Post by nbeligh01 on July 6, 2009.
(0)
nbeligh01
Member
1 points
8 Posts
07-03-2009 10:35 AM |
Hi all,
My college developped a web site with cake php, we added a new part to generate xml stream from that web site with a different url for each stream corresponding to one thing.
So my task was to create a component with silverlight to read that stream, here is a part of typical code I used :
1 private void readXmlFlux(string uri) 2 { 3 WebClient xmlclient = new WebClient(); 4 xmlclient.OpenReadCompleted += new OpenReadCompletedEventHandler(xmlclient_OpenReadCompleted); 5 6 //URL du flux rss 7 Uri UriFeed = new Uri(uri); 8 if (!xmlclient.IsBusy) 9 { 10 xmlclient.OpenReadAsync(UriFeed); 11 } 12 } 13 14 void xmlclient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 15 { 16 XDocument document = XDocument.Load(e.Result); 17 .... 18 .... 19 }
Yet, my code never goes in method "xmlclient_OpenReadCompleted", my application stand waiting for reading end wich don't end.
I verified my url (->uri) wich is correct when I put it on browser : It shows me Xml
I passed a day searching why it blocks in that method
OpenReadAsync(UriFeed); and found no solution
So, if anyone knows or has an ideé about the source of the problem, plz let me know :)
Tks;
jay nana...
Contributor
3388 points
624 Posts
07-03-2009 10:40 AM |
try to remove if condition for IsBusy and check again.
07-03-2009 10:52 AM |
In fact , it was not there , I added it to verify .
Removing it don't change anythig.
It's coming from that method called "OpenReadAsync" wich work asynchronously without terminating :|
07-03-2009 10:55 AM |
Have you tried DownloadStringAsync instead of OpenReadAsync? because I was able to do that while reading xml feeds from server.
07-03-2009 11:06 AM |
Hey I have prepared working example for you. grab from here:
http://cid-b55690d11b67401d.skydrive.live.com/self.aspx/Public/ReadXML.zip
07-06-2009 4:30 AM |
Thank you Jay for the sample,
Simple & clear, it works but the problem is that's exactly what I did the diiference is that I have my page.xaml in wich I instantiate a class named MyxmlReader when pushing a button, in that class I have public methods like readxmlFlux(uri) which is called from page.xaml and wich contains this treatement you gave to me.
so I think the problem is from Instantianting a class and using an asynchronous method in it ... may be the class is closed before the work ends ... OR ??
I hope you understood my logic, may be you had encountred a same case ??
thank you ;
07-06-2009 6:52 AM |
Hi,
I changed my code logic to correct that error, yet I received a system.Security.SecutityException in "XmlReader reader = XmlReader.Create(e.Result); "
{System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid. Check InnerException for exception details. ---> System.Security.SecurityException ---> System.Security.SecurityException: Security error. at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState) at System.Net.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState) --- End of inner exception stack trace --- at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result) --- End of inner exception stack trace --- at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() at System.Net.DownloadStringCompletedEventArgs.get_Result() at MediStat.Page.xmlclient_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e) at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e) at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)}
I'm using an Asp.net project to host the silverlight application.
Do you have any suggestions ?
Thank you;
07-06-2009 6:56 AM |
can you share the url you are trying to read xml from?
07-06-2009 9:24 AM |
It's a local url it works fine , it's generated by a site developped with cake php by a collegue, he removed authentification from that url also.