Tips and Tricks in a world of Mix

Private WebServiceStatusCode As String

Public Function ConnectionAvailable(ByVal strServer As String) As Boolean
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()
Return True
' Other status - Server or connection not available
WebServiceStatusCode = rspFP.StatusCode.ToString()

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: Logo

You are commenting using your 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: