Select to view content in your preferred language

REST Morning wake up

1336
13
08-06-2010 05:53 AM
andrewj_ca
Frequent Contributor
REST Morning wake up

I've read alot of posts regarding slow operation or errors accessing a rest service first thing in the morning or the first operation of the day.  I thought I'd attach a little application I use to prevent this.  It also has email notification for when a service stops and starts.  I figure it works for us and may work for you.  After using this app, please feel free to send me your comments or issues.  I've included two services in the list for an example.  Cheers.

Service List (xml)

Web Service Monitor Executable (exe)
Tags (2)
0 Kudos
13 Replies
RobertScheitlin__GISP
MVP Emeritus
mcnaughty79,

   Can you also provide the source for the web service monitor app?
0 Kudos
andrewj_ca
Frequent Contributor
Unfortunately I won't be able to legally share the source code but I am willing to help with any questions you may have.  Cheers
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
mcnaughty79,

  Shame... I just can't run an executable from an unknown party when I can not verify the code is doing only what it claims to do.
0 Kudos
andrewj_ca
Frequent Contributor
Would a snippet of the code suffice or do you require the complete source? I guarantee there is nothing malicious in the executable.
0 Kudos
CaseyBentz
Frequent Contributor
Robert,

I have an application that runs as a scheduled task that basically parses my /ArcGIS/rest/services directory and opens each service.  I wrote it a while ago, with no documentation, so take it as it is.

I have attached a zip file, which I have had no luck with attaching, so I have also include the source code that you could copy into a console appliction.

Imports System.Threading
Imports System.Net

Module agsServicesWakeUp
    Sub Main()
        readHTML()
    End Sub
    Private Sub readHTML()
        Try
            Dim objWebClient As New WebClient
            objWebClient.UseDefaultCredentials = True
            Dim aRequestHTML() As Byte = objWebClient.DownloadData("http://yourservername/ArcGIS/rest/services") 'Change to your server
            Dim counter As Integer = 0
            Dim html As String = ""

            Do While counter < aRequestHTML.Length
                html += Chr(aRequestHTML.GetValue(counter))
                counter = counter + 1
            Loop

            Dim serviceFolderArray() As Object = {}
            Dim i As Integer = 0
            Dim j As Integer = 1
            Dim count As Integer = 0
            Do While i < html.Length
                i = InStr(j, html, "/ArcGIS/rest/services/")
                If i > 0 Then
                    j = InStr(i, html, ">") - 1
                    Dim serviceFolder() As String = {html.Substring(i - 1, j - i)}
                    Array.Resize(serviceFolderArray, count + 1)
                    Array.ConstrainedCopy(serviceFolder, 0, serviceFolderArray, count, 1)
                    count = count + 1
                    i = j
                Else
                    i = 0
                    j = 1
                    count = 0
                    Exit Do
                End If
            Loop

            Dim k As Integer = 0
            Dim servicesArray() As Object = {}

            Do While k < serviceFolderArray.Length
                objWebClient.UseDefaultCredentials = True
                Dim serviceRequestHTML() As Byte = objWebClient.DownloadData("http://yourservername" + serviceFolderArray(k).ToString) 'Change to your server name
                counter = 0
                html = ""

                Do While counter < serviceRequestHTML.Length
                    html += Chr(serviceRequestHTML.GetValue(counter))
                    counter = counter + 1
                Loop

                Do While i < html.Length
                    i = InStr(j, html, serviceFolderArray(k).ToString + "/")

                    If i > 0 Then
                        j = InStr(i, html, ">") - 1
                        Dim service() As String = {html.Substring(i - 1, j - i)}
                        Array.Resize(servicesArray, count + 1)
                        Array.ConstrainedCopy(service, 0, servicesArray, count, 1)
                        count = count + 1
                        i = j
                    Else
                        i = 0
                        j = 1
                        Exit Do
                    End If
                Loop
                k += 1
            Loop

            callURL(servicesArray)
            callURL(servicesArray)

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
    Private Sub callURL(ByVal servicesArray As Object, Optional ByVal sleep As Integer = 100)
        Dim i As Integer = 0
        Dim webApp
        webApp = CreateObject("InternetExplorer.Application")
        webApp.Visible = False

        Do While i < servicesArray.Length
            Console.WriteLine("http://yourservername" + servicesArray(i).ToString) 'Change to your server name
            webApp.Navigate("http://yourservername" + servicesArray(i).ToString) 'Change to your server name
            Thread.Sleep(sleep)
            i += 1
        Loop

        webApp.quit()
        webApp = Nothing
    End Sub
End Module
0 Kudos
andrewj_ca
Frequent Contributor
Quick snippet:

    Public Function PingWebService(ByVal serviceURL As String, ByVal sType As String) As Boolean
        Try
            Dim httpreq As Net.HttpWebRequest = Net.WebRequest.Create(serviceURL)
            Dim httpres As Net.HttpWebResponse = httpreq.GetResponse()
            Dim httpr As Boolean = False
            If httpreq.HaveResponse = True AndAlso Not (httpres Is Nothing) Then
                Dim r As New IO.StreamReader(httpres.GetResponseStream())
                Dim str As String = r.ReadToEnd
                Select Case sType
                    Case "REST"
                        If Not str.IndexOf("<div class=" & Chr(34) & "restErrors" & Chr(34) & ">", 0) > -1 Then
                            httpr = True
                        End If
                    Case "WMS"

                End Select
            End If
            Return httpr
        Catch ex As Exception
            Return False
        End Try
    End Function

Use:

PingWebService("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer","REST")

Return true or false
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Andrew and Casey,

   Thanks for the code. I believe that this is a mute point with ArcGIS Server 10 though. In 10 the ArcGIS SOC Monitor (that didn't do anything in 9.3) handles keeping the service awake.
0 Kudos
andrewj_ca
Frequent Contributor
No problem Robert, but lets be honest.  No topic is ever mute when it comes to ArcGIS.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Andrew,

  Good point. Yours and Casey's code will help all of those that will not be upgrading to 10 right away.
0 Kudos