Link to home
Start Free TrialLog in
Avatar of isnoc
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.xsl")

Dim xmlhttp
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", sourceFile, false
xmlhttp.Send


set source = Server.CreateObject("Microsoft.XMLDOM")
source.async = false
source.loadxml(xmlhttp.ResponseText)

set style = Server.CreateObject("Microsoft.XMLDOM")
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>
Avatar of peterxlane
peterxlane

Try is like this:

Function getXML(sourceFile)
      Dim styleFile
      Dim source, style
      styleFile = Server.MapPath("..\news.xsl")

      Dim xmlhttp
      Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
      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("Microsoft.XMLDOM")
            source.async = False
            source.loadxml(xmlhttp.ResponseText)

            Set style = Server.CreateObject("Microsoft.XMLDOM")
            style.async = False
            style.load(styleFile)

            getXML = source.transformNode(style)
            Set source = Nothing
            Set style = Nothing             
      End If
      
End Function
ASKER CERTIFIED SOLUTION
Avatar of peterxlane
peterxlane

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial