Skip to main content

Microsoft Silverlight

Read xml stream from urlRSS Feed

(0)

nbeligh01
nbeligh01

Member

Member

1 points

8 Posts

Read xml stream from url

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 nanavati
jay nana...

Contributor

Contributor

3388 points

624 Posts

Re: Read xml stream from url

try to remove if condition for IsBusy and check again.

Jay K Nanavaty
www.technologyopinion.com
Mark as answer if it helps. It will also help others...

nbeligh01
nbeligh01

Member

Member

1 points

8 Posts

Re: Read xml stream from url

 

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 :|

jay nanavati
jay nana...

Contributor

Contributor

3388 points

624 Posts

Re: Re: Read xml stream from url

Have you tried DownloadStringAsync instead of OpenReadAsync? because I was able to do that while reading xml feeds from server.

Jay K Nanavaty
www.technologyopinion.com
Mark as answer if it helps. It will also help others...

jay nanavati
jay nana...

Contributor

Contributor

3388 points

624 Posts

Re: Re: Re: Read xml stream from url

Hey I have prepared working example for you. grab from here:

http://cid-b55690d11b67401d.skydrive.live.com/self.aspx/Public/ReadXML.zip

Jay K Nanavaty
www.technologyopinion.com
Mark as answer if it helps. It will also help others...

nbeligh01
nbeligh01

Member

Member

1 points

8 Posts

Re: Re: Re: Read xml stream from url

 Thank you Jay for the sample,

Simple & clear, it works but the problem is that's exactly what I did Tongue Tied 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 ;

nbeligh01
nbeligh01

Member

Member

1 points

8 Posts

Re: Re: Re: Read xml stream from url

 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;

jay nanavati
jay nana...

Contributor

Contributor

3388 points

624 Posts

Re: Re: Re: Re: Read xml stream from url

can you share the url you are trying to read xml from?

Jay K Nanavaty
www.technologyopinion.com
Mark as answer if it helps. It will also help others...

nbeligh01
nbeligh01

Member

Member

1 points

8 Posts

Re: Re: Re: Re: Read xml stream from url

 It's a local url Tongue Tied it works fine , it's generated by a site developped with cake php by a collegue, he removed authentification from that url also.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities