How to detect a web service is running?

Parkyboy

New member
Joined
Feb 24, 2005
Messages
3
Programming Experience
1-3
Hi,

I am newbie in web service in vb .net. I want to develop a win form that is able to detect a web service is running irregardless of whether the web service is being placed or URL of the web service has changed? Can someone kindly give me a pointer or two? Thanks.
 
Hi everyone,

I have found out the solution myself and I am replying so if anyone needs it might find it helpful. Basically is to use the WebRequest function provided by System.Net. Here is the VB codes:

Imports System.Net
Imports localhost.Service1

Public Function WebServiceRunning() As Boolean
Try

Dim colProcess As New localhost.Service1
Dim siteUri As New System.Uri(colProcess.Url.ToString)
Dim webRequest As System.Net.WebRequest = System.Net.WebRequest.Create(siteUri)
Dim webResponse As System.Net.WebResponse = webRequest.GetResponse()

If IsNothing(webResponse) Then
WebServiceRunning = False
Else
WebServiceRunning = True
End If

Catch ex As Exception
WebServiceRunning = False
End Try
End Function

End Class

Note: You need to do a web reference to the web service that you are consuming. The Imports localhost.service1 is the web reference that I am consuming. You also might want to set the URL property of the web reference to 'Dynamic' so that if the URL of the web service changes, you only need to update location in the App.Config file of your window application without need to recompile your application.

regards,
Parkyboy
 
Back
Top