[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

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.
0
tegronakron
Asked:
tegronakron
1 Solution
 
ZippitCommented:
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now