473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determinate if the connection to internet is OK

ad
Hi,
It will fail to call a web service when the connection to internet is not
OK.

I wnant to check the connection to internet before call a web service.

How to determinate if the connection to internet is OK?
Nov 17 '05 #1
1 1932
Hi,

The Offline Application Block provides a mechanism to determine if you
have an internet connection. Here is the class that implements this:
using System;
using System.Runtime. InteropServices ;
using System.Xml.XPat h;
using System.Configur ation;
using Microsoft.Appli cationBlocks.Co mmon;

namespace Microsoft.Appli cationBlocks.Sm artClient.Offli ne
{
/// <summary>
/// This is a simple implementation of a ConnectionDetec tionStrategy.
It uses the WinINet
/// function GetInternetConn ectionState to detect whether you are
actually connected to
/// another system anywhere. This strategy is not smart enough to tell
if you can talk
/// to a particular host -- it merely checks to see that you can talk
to *any* host.
/// This means that there is an ethernet connection to another
computer or a network,
/// or that a modem is connected.
/// </summary>
public class WinINetDetectio nStrategy
{
private int pollInterval;

/// <summary>
/// Public constant used in test code.
/// </summary>
public const int MinimumPollingI ntervalInSecond s = 1;

[DllImport("wini net.dll")]
private extern static bool InternetGetConn ectedState( out int
connectionDescr iption, int reservedValue ) ;

/// <summary>
/// Getter property to retrieve the polling interval in seconds
/// </summary>
/// <value>Pollin g interaval in seconds</value>
public int PollInterval { get { return pollInterval; }}

/// <summary>
/// Query method to cause provider to actively detect the connection
state
/// </summary>
/// <returns>True if provider believes we are connected</returns>
public bool IsConnected()
{
int connectionDescr iption = 0;
return InternetGetConn ectedState(out connectionDescr iption, 0);
}

/// <summary>
/// IProvider.Initi alize method implementation. Retrieves
configuration information from app.config file
/// </summary>
/// <param name="configura tionNode">XmlNo de to parse for
configuration information</param>
public void Initialize(XPat hNavigator configurationNo de)
{
XPathNodeIterat or iter =
configurationNo de.Select("poll ingInterval");
iter.MoveNext() ;

pollInterval = GetCurrentPolli ngInterval(iter .Current.Value) ;
if(pollInterval < MinimumPollingI ntervalInSecond s)
{
throw new
ConfigurationEx ception(Provide rsResourceTable .GetString(Prov idersResourceTa ble.ConnectionM anagerPollingIn tervalMessage)) ;
}
}

private int GetCurrentPolli ngInterval(stri ng pollingInterval String)
{
try
{
return Convert.ToInt32 (pollingInterva lString);
}
catch(FormatExc eption e)
{
throw new
ConfigurationEx ception(Provide rsResourceTable .GetString(Prov idersResourceTa ble.PollingInte rvalShouldBeNum eric),
e);
}
}
}
}
If you use this class, then you'll want to call the IsConnected()
method to determine connectivety. You can learn more about the Offline
block at:

http://msdn.microsoft.com/library/de...fline-ch01.asp
Thanks,

Sayed Y. Hashimi

http://www.sayedhashimi.com
Shameless Book Plug: Service-Oriented Smart Clients with .NET 2.0
http://www.amazon.com/exec/obidos/tg...glance&s=books

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2803
by: Peter Flynn | last post by:
I'm having trouble finding example code to detect the presence of an Internet connection. It doesn't seem to be a very frequently asked question, as all I need is the answer yes or no (is the user connected or not). I'm not interested in speed detection or any other aspect of the connection, just its existence or not. The reason is to be able to intercept link clicks on a CD-based set of HTML pages and pop up a warning if there is no...
3
6625
by: Jonny | last post by:
Hi, Please could you tell me how to check for an internet connection in C. I'm using Windows 2000. Many Thanks, Jonny
2
1797
by: ad | last post by:
The user of my asp.net program use Sql2005 or Sql2005 express as database, both are possible. I have try both version of data base, I found: If I use Sql2005 express, the Data Source in connection string will be ..\SQLEXPRESS, like: Data Source=.\SQLEXPRESS;Initial Catalog=myDB;Integrated Security=True But I use Sql2005 , the Data Source in connection string can be use (local), like:
2
2424
by: Mahesh Devjibhai Dhola | last post by:
Hi, I want to develop p2p (peer-to-peer) communication connection for chat in ..Net (Lang: c# - preferable) NOTE: if two LAN are behind their own router then also it should work as yahoo, msn messenger works. Let me explain scenario: In yahoo: - We login to yahoo server from yahoo messenger (yahoo server listens at
1
1895
by: ad | last post by:
I want to determinate if a value in a Text is digital or character. How can I determinate it with Javascript
3
4044
by: danielmcinerney | last post by:
i am trying to set up internet connection sharing between a vista machine (host) and an XP machine (client). i have followed guidelines from various pages on the internet but i still cannot get it working. here is what ive done i gave up on using dhcp addressing between the host and client as this wasnt working so i tried using static ip's instead. the host and the server are connected by a wired connection (through a switch). the host is...
6
3132
by: =?Utf-8?B?QnNtZW5nZW4=?= | last post by:
I am trying to make sure that the local connection is up. I have presently been using the NetworkChange.NetworkAvailabilityChanged Event for this. Is there a better way to do this? Also, I want to test to see if the Internet Connection is up. I need the Internet to be up for the Web Services I am calling. Is it better to test the Internet Connection through Pinging an IP Address (I presently do 3 ping failures for it to be down) or...
17
5555
by: John Salerno | last post by:
Let me see if this question even makes sense...I'm reading Core Python Programming and I jumped ahead to the more specific topics like network programming. I plan to follow along with the example in that chapter and create a socket connection between my desktop and laptop. However, these two computers are already connected on my home network (using the Windows Network Setup Wizard), so I was wondering if this will have any effect on what...
1
2258
by: =?Utf-8?B?QiBTaW5naA==?= | last post by:
Hi Scenario 1) Host - XP Laptop with internet connection using Sky Broadband Wireless Router Netgear DG834GT 2) MS Virtual Server 2005 - I have deployed an XP MS Virtual Server 2005 to act as a virtual machine
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.