Reading RSS through asp.net

C

Chet C

I am trying to make a simple RSS reader using asp.net (VB) and am
getting an error when I run the project locally (works fine after being
published) Here is my basic code:

Sub Page_Load(sender as Object, e as EventArgs)

Dim url As String = _
"http://www.dailyaudiobible.com/wordpress/?feed=rss2"

recentPosts.DataSource = GetRSSFeed(url)
'recentPosts is a gridview control on the aspx page.

recentPosts.DataBind()
End Sub

Function GetRSSFeed(ByVal strURL As String) As DataTable

'Get the XML data
Dim reader As XmlTextReader = New XmlTextReader(strURL)

'return a new DataSet
Dim ds As DataSet = New DataSet()

ds.ReadXml(reader)

Return ds.Tables(2)

End Function

This page works fine when I publish it to my web server. When I run it
locally (http://localhost:9999/xxxxx) I get the error "Cannot find table
2" on the "Return ds.Tables(2)" line of GetRSSFeed. I originally was
guessing that this has something to do with my proxy/firewall (ISA
Server 2004) but I set up a monitor and watched it and don't see
anything being rejected. Could it be due to a permissions setting in
Visual Studio? The reason I wonder if it's not a firewall thing is
because the published server sits behind the same firewall. I'm working
on XP Pro, the publishing server is Server 2003.

I've tried several different RSS and Atom feeds with the same results,
and have tried some other xml reader structures also... same result. I
have also tried the code on my home computer (disabled all firewalls
temporarily) with the same result; sure seems to be something with
either XP IIS server or the VS.NET environment...

Any help would be appreciated; thank you!
 
G

Guest

I am trying to make a simple RSS reader using asp.net (VB) and am
getting an error when I run the project locally (works fine after being
published) Here is my basic code:

Sub Page_Load(sender as Object, e as EventArgs)

Dim url As String = _
"http://www.dailyaudiobible.com/wordpress/?feed=rss2"

recentPosts.DataSource = GetRSSFeed(url)
'recentPosts is a gridview control on the aspx page.

recentPosts.DataBind()
End Sub

Function GetRSSFeed(ByVal strURL As String) As DataTable

'Get the XML data
Dim reader As XmlTextReader = New XmlTextReader(strURL)

'return a new DataSet
Dim ds As DataSet = New DataSet()

ds.ReadXml(reader)

Return ds.Tables(2)

End Function

This page works fine when I publish it to my web server. When I run it
locally (http://localhost:9999/xxxxx) I get the error "Cannot find table
2" on the "Return ds.Tables(2)" line of GetRSSFeed. I originally was
guessing that this has something to do with my proxy/firewall (ISA
Server 2004) but I set up a monitor and watched it and don't see
anything being rejected. Could it be due to a permissions setting in
Visual Studio? The reason I wonder if it's not a firewall thing is
because the published server sits behind the same firewall. I'm working
on XP Pro, the publishing server is Server 2003.

I've tried several different RSS and Atom feeds with the same results,
and have tried some other xml reader structures also... same result. I
have also tried the code on my home computer (disabled all firewalls
temporarily) with the same result; sure seems to be something with
either XP IIS server or the VS.NET environment...

Any help would be appreciated; thank you!

I think, ASPNET accout has no rights on proxy and has been rejected.

Try to see a body of the response:

doc.Load(reader)
Response.Write(doc.InnerText)
reader.Close()
 
M

Mark Fitzpatrick

First, you should always check to make sure that the dataset loads properly
and that there are tables by checking the datasets tables.count property.

Have you tried doing a Trace.Write to dump the contents of the dataset or
each of the tables in the dataset? That could give you an idea of exactly
the kind of data it's getting back. Also, are both your local version and
the hosted running the same version of ASP.Net?
 
G

Guest

doc.Load(reader)
Response.Write(doc.InnerText)
reader.Close()- Hide quoted text -

I forgot to mention: Dim doc as System.Xml.XmlDocument = New
System.Xml.XmlDocument
 
C

Chet C

Mark said:
First, you should always check to make sure that the dataset loads properly
and that there are tables by checking the datasets tables.count property.

Have you tried doing a Trace.Write to dump the contents of the dataset or
each of the tables in the dataset? That could give you an idea of exactly
the kind of data it's getting back. Also, are both your local version and
the hosted running the same version of ASP.Net?
I have checked my dataset. It has only 2 tables (0,1) and both of them
have no rows, so something is not loading correctly (thus the error
about there not being a table 2). If I run it on my publishing web
server (still on the same firewall) it works ok. - lots of tables with
the rss feed, authors, comments, and some other tables I don't need.
 
C

Chet C

Alexey said:
I think, ASPNET accout has no rights on proxy and has been rejected.

Try to see a body of the response:

doc.Load(reader)
Response.Write(doc.InnerText)
reader.Close()

What is this "doc" object? I know of the document object at the client
side, but don't see how I could mix that with the reader object on the
server side.

Diving into this a little more I thought it might be related to the
<trust> section in my web.config file, which I don't know too much
about, but tried adding this:

<trust level="Medium" originUrl=".*/"/>

but that doesn't help either. It causes the app to error out on the line
BEFORE the one that tries to return ds.Tables(2). The error on
"ds.ReadXml(reader)" is "Request for the permission of type
"System.Net.WebPermission...failed." and one of the troubleshooting tips
is "Retrieve data from the same Web server from which it was deployed...
which is exactly what I DON'T want to do; I want to retrieve RSS from
another server.
 
G

Guest

Chet C said:
What is this "doc" object? I know of the document object at the client
System.Xml.XmlDocument

but that doesn't help either. It causes the app to error out on the line
BEFORE the one that tries to return ds.Tables(2). The error on
"ds.ReadXml(reader)" is "Request for the permission of type
"System.Net.WebPermission...failed." and one of the troubleshooting tips
is "Retrieve data from the same Web server from which it was deployed...
which is exactly what I DON'T want to do; I want to retrieve RSS from
another server.

Try to set default proxy, for example:

Dim url As String = "http://www.dailyaudiobible.com/wordpress/?feed=rss2"

Dim wr As System.Net.HttpWebRequest =
CType(System.Net.HttpWebRequest.Create(url), System.Net.HttpWebRequest)
wr.Proxy = New System.Net.WebProxy("name_of_your_proxy:80")

Dim reader As System.Xml.XmlTextReader = New
System.Xml.XmlTextReader(wr.GetResponse().GetResponseStream())
Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument()

doc.Load(reader)
Response.Write(doc.InnerText)
reader.Close()
 
C

Chet C

Alexey said:
Try to set default proxy, for example:

Dim url As String = "http://www.dailyaudiobible.com/wordpress/?feed=rss2"

Dim wr As System.Net.HttpWebRequest =
CType(System.Net.HttpWebRequest.Create(url), System.Net.HttpWebRequest)
wr.Proxy = New System.Net.WebProxy("name_of_your_proxy:80")

Dim reader As System.Xml.XmlTextReader = New
System.Xml.XmlTextReader(wr.GetResponse().GetResponseStream())
Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument()

doc.Load(reader)
Response.Write(doc.InnerText)
reader.Close()
Ok... we're getting SOMEWHERE.

I had to use port 8080 instead of 80, but using this code I can read the
XML file into the browser using the XMLDocument.

I can write the contents of the XMLDocument object to the browser as
indicated in your post. I can also read them into my dataset by putting
my ds.ReadXML(reader) line right after the doc.Load command (before I
close the reader). However, it still only contains two datatables, (0,1)
when it should have more, and neither of the datatables contain any
rows. Here are the schemas of the two datatables it returns for my
example rss feed:

DT 0 - COLS: 7 ROWS: 0
COLUMNS: address, phone, photo, firstname, lastname, AvatarSize, memberid,

DT 1 - COLS: 2 ROWS: 0
COLUMNS: avatar, memberid,

I've tried this with several feeds from several sources and get the same
thing; maybe it's part of the standard, but I'm just not getting that
third (or subsequent) tables when I read the xml in through the
ds.ReadXML method.

To summarize :
1. doc.Load(reader) (doc = xmlDocument) returns an XML document I can
write to the browser. I can't do any databinding that I know of, though,
which I want.

2. ds.readXML(reader) (ds = dataset) returns a 2 table dataset with no data
 
C

Chet C

Chet said:
DT 0 - COLS: 7 ROWS: 0
COLUMNS: address, phone, photo, firstname, lastname, AvatarSize, memberid,

DT 1 - COLS: 2 ROWS: 0
COLUMNS: avatar, memberid,

I might be losing it, but one of these datatables (0) looks strangely
similar to a table in my project that keeps track of membership to the
site. I am using a template provided by Microsoft (club site, I think it
was called) and the table it uses to keep track of members is called
"MemberInfo." The fields in MemberInfo are:

address, phone, firstname, lastname, avatar, memberid

That is so similar to DT 0 above that I can't help but wonder if they're
related; avatar/AvatarSize is the only difference in field names. There
are no tables similar to DT 1 that I can see, though...

For what it's worth...
 
C

Chet C

Chet said:
I might be losing it, but one of these datatables (0) looks strangely
similar to a table in my project that keeps track of membership to the
site. I am using a template provided by Microsoft (club site, I think it
was called) and the table it uses to keep track of members is called
"MemberInfo." The fields in MemberInfo are:

address, phone, firstname, lastname, avatar, memberid

Doesn't look like these are related - maybe it's part of the RSS
specification, but I made a completely new asp.net site (no template
site, just default.aspx and web.config and the code for retrieving RSS
into a datatable) and it behaves the same way (2 tables with no data)
 
G

Guest

Chet C said:
indicated in your post. I can also read them into my dataset by putting my
ds.ReadXML(reader) line right after the doc.Load command

Bad idea, because at this point the reader is positioned at the end of the
stream.

An example with the XmlDocument I've sent you to find the error you get from
your proxy. If you still need that code, you can convert an XmlDocument
object into a DataSet, or close and open reader again.

Example of XmlDocument -> DataSet conversion

doc.Load(reader)
Response.Write(doc.InnerText)

Dim reader2 As System.Xml.XmlNodeReader = New System.Xml.XmlNodeReader(doc)
Dim ds As DataSet = New DataSet()
ds.ReadXml(reader2)

And now you should have all your tables.

Note, you can do
ds.Tables.Count

to find a number of the tables



If you don't need an XmlDocument anymore (I guess the problem with the
proxy is solved now), simply delete the code I gave you, except the proxy
and

XmlTextReader(wr.GetResponse().GetResponseStream());

Hope it helps
 
G

Guest

Well...

It still wasn't working, I don't know what I am doing wrong...

This is working for me

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim url As String = _
"http://www.dailyaudiobible.com/wordpress/?feed=rss2"

recentPosts.DataSource = GetRSSFeed(url)
'recentPosts is a gridview control on the aspx page.
recentPosts.DataBind()

End Sub

Function GetRSSFeed(ByVal strURL As String) As DataTable

Dim wr As System.Net.HttpWebRequest = _
CType(System.Net.HttpWebRequest.Create(strURL),
System.Net.HttpWebRequest)
wr.Proxy = New System.Net.WebProxy("name_of_your_proxy:8080")

'NOTE, if you have no proxy, use wr.Proxy = New System.Net.WebProxy()

'Get the XML data
Dim reader As System.Xml.XmlTextReader = _
New System.Xml.XmlTextReader(wr.GetResponse().GetResponseStream())

'return a new DataSet
Dim ds As DataSet = New DataSet()
ds.ReadXml(reader)

Return ds.Tables(2)

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top