isnoc
asked on
Webservice not available - How to error check?
We use the following code to display the news from the rugby site. It displays the news directly on our home page.
The question I have how can I check that the service is actually available by the time the code gets to the line
<%= getXML("http://www.rugbyworldcup.com/en/rss") %>
At present if the site is down it gives an ugly error. I want to present a nicely formatted error. Can someone suggest a peice of code that checks if the site that we are connecting to is up or not and then display an error message if it is down or not reacable
<%
Function getXML(sourceFile)
dim styleFile
dim source, style
styleFile = Server.MapPath("..\news.xs l")
Dim xmlhttp
Set xmlhttp = Server.CreateObject("Micro soft.XMLHT TP")
xmlhttp.Open "GET", sourceFile, false
xmlhttp.Send
set source = Server.CreateObject("Micro soft.XMLDO M")
source.async = false
source.loadxml(xmlhttp.Res ponseText)
set style = Server.CreateObject("Micro soft.XMLDO M")
style.async = false
style.load(styleFile)
getXML = source.transformNode(style )
set source = nothing
set style = nothing
End Function
%>
<table width="558" height="130" border="0" cellpadding="20" cellspacing="0" align="center" bgcolor="#FFFFFF">
<tr>
<td>
<%= getXML("http://www.rugbyworldcup.com/en/rss") %>
</td>
</tr>
</table>
The question I have how can I check that the service is actually available by the time the code gets to the line
<%= getXML("http://www.rugbyworldcup.com/en/rss") %>
At present if the site is down it gives an ugly error. I want to present a nicely formatted error. Can someone suggest a peice of code that checks if the site that we are connecting to is up or not and then display an error message if it is down or not reacable
<%
Function getXML(sourceFile)
dim styleFile
dim source, style
styleFile = Server.MapPath("..\news.xs
Dim xmlhttp
Set xmlhttp = Server.CreateObject("Micro
xmlhttp.Open "GET", sourceFile, false
xmlhttp.Send
set source = Server.CreateObject("Micro
source.async = false
source.loadxml(xmlhttp.Res
set style = Server.CreateObject("Micro
style.async = false
style.load(styleFile)
getXML = source.transformNode(style
set source = nothing
set style = nothing
End Function
%>
<table width="558" height="130" border="0" cellpadding="20" cellspacing="0" align="center" bgcolor="#FFFFFF">
<tr>
<td>
<%= getXML("http://www.rugbyworldcup.com/en/rss") %>
</td>
</tr>
</table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Function getXML(sourceFile)
Dim styleFile
Dim source, style
styleFile = Server.MapPath("..\news.xs
Dim xmlhttp
Set xmlhttp = Server.CreateObject("Micro
xmlhttp.Open "GET", sourceFile, False
xmlhttp.Send
If (xmlhttp.readyState <> 4) OR (xmlhttp.Status <> 200) Then
xmlhttp.Abort
getXML = "ERROR"
Else
Set source = Server.CreateObject("Micro
source.async = False
source.loadxml(xmlhttp.Res
Set style = Server.CreateObject("Micro
style.async = False
style.load(styleFile)
getXML = source.transformNode(style
Set source = Nothing
Set style = Nothing
End If
End Function