?
Solved

Webservice not available - How to error check?

Posted on 2006-04-13
4
Medium Priority
?
515 Views
Last Modified: 2008-01-09
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>
0
Comment
Question by:isnoc
  • 2
2 Comments
 
LVL 12

Expert Comment

by:peterxlane
ID: 16446806
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
 
LVL 12

Accepted Solution

by:
peterxlane earned 500 total points
ID: 16446845
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question