Tips and Tricks in a world of Mix

Private WebServiceStatusCode As String

Public Function ConnectionAvailable(ByVal strServer As String) As Boolean
Try
Dim reqFP As HttpWebRequest = DirectCast(HttpWebRequest.Create(strServer), HttpWebRequest)

Dim rspFP As HttpWebResponse = DirectCast(reqFP.GetResponse(), HttpWebResponse)
If HttpStatusCode.OK = rspFP.StatusCode Then
' HTTP = 200 - Internet connection available, server online
WebServiceStatusCode = rspFP.StatusCode.ToString()
rspFP.Close()
Return True
Else
' Other status - Server or connection not available
WebServiceStatusCode = rspFP.StatusCode.ToString()
rspFP.Close()

Return (False)
End If
Catch generatedExceptionName As WebException
' Exception - connection not available
WebServiceStatusCode = generatedExceptionName.Message
Return False
End Try
End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tag Cloud

%d bloggers like this: