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>
isnocAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peterxlaneCommented:
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
0
peterxlaneCommented:
and to make it even tighter, you could do it this way:

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
            If source.loadxml(xmlhttp.ResponseText) Then
                  Set style = Server.CreateObject("Microsoft.XMLDOM")
                  style.async = False
                  If style.load(styleFile) Then
                        getXML = source.transformNode(style)
                  Else
                        getXML = "UNABLE TO LOAD XSL FILE"
                  End If
            Else
                  getXML = "UNABLE TO LOAD REMOTE XML"
            End If
            Set source = Nothing
            Set style = Nothing             
      End If
      
End Function

By putting those Load and LoadXML methods in an if statement you can be sure that they are successful before proceeding to the next step.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.