Using VB.Net 2005 how do I test for a web service to determine if it running?

What is the best practice way to programmatically determine if a web service is running?  This must be done using MS VB 2005.
tegronakronAsked:
Who is Participating?
 
ZippitConnect With a Mentor Commented:
If you just want to check if the webservice is responding, the attached code will work.  Essentially a webservice is just a web page (URL) that accepts standardized XML in the request and responds with standardized XML.  So the attached code just checks if the passed in URL (this would be the URL where the webservice is hosted, ie http://www.mydomain.com/mywebsvc.asmx ) is resolvable and is responding.  By default it waits 5 seconds, but you can change this easily.

HTH
Private Function isSiteAccessible(ByVal url As String) As Boolean
        Dim rv As Boolean = False
        Dim req As HttpWebRequest = WebRequest.Create(url)
        Dim res As HttpWebResponse = Nothing
 
        req.Timeout = 5000      ' 5 seconds
        'req.UserAgent = "My Web Checker"
 
        Try
            res = CType(req.GetResponse(), HttpWebResponse)
 
            If res.StatusCode = 200 Then
                rv = True
            End If
 
        Catch ex As Exception
 
        End Try
 
        Return rv
    End Function

Open in new window

0
 
tegronakronAuthor Commented:
Thanks,  this worked as I had hoped.
0
All Courses

From novice to tech pro — start learning today.