Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Webservice call work on dial up?

2 views
Skip to first unread message

Ying-Shen Yu[MSFT]

unread,
Feb 21, 2004, 1:09:36 AM2/21/04
to
Hi Mark,

To my understanding , you would like to check if the network connection is
available before invoking a web service method.

You may try P/invoking, the function
IsNetworkAlive with NETWORK_ALIVE_WAN flag.
to get the connection state of the WAN connection.
You may also try the function
IsDestinationReachable, it wrapper the ping function, then you can know if
the server is reachable.

Does it solve your problem?
Please feel free to reply this thread if you have any problems on it.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.

Ying-Shen Yu[MSFT]

unread,
Feb 23, 2004, 8:48:35 PM2/23/04
to
Hi mark,
Here is a small snippet to show you how to invoke these 2 APIs in C#.

In my further research, both APIs have their limitations(e.g.
IsDestinationReachable depends on if the server would respond to Ping), so
if you have problem in using these APIs, maybe you can try using TcpClient
class and connecting to that web service first to see if the service is
available, when your application starting up.

Please feel free to reply to this thread, if you need further help on it.
Thanks!

<code>
using System;
using System.Runtime.InteropServices;

namespace NetSense
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
int NETWORK_ALIVE_LAN = 0x00000001;
int NETWORK_ALIVE_WAN = 0x00000002;
int NETWORK_ALIVE_AOL = 0x00000004;
if (IsNetworkAlive(ref NETWORK_ALIVE_WAN))
Console.WriteLine("Wan Alive");
if (IsNetworkAlive(ref NETWORK_ALIVE_LAN))
Console.WriteLine("Lan Alive");
if (IsNetworkAlive(ref NETWORK_ALIVE_AOL))
Console.WriteLine("Aol Alive");

string hostname = "www.microsoft.com";
//for simplicity, we do not care about the QocInfo
if (IsDestinationReachable(hostname,IntPtr.Zero))
Console.WriteLine("{0} is reachable",hostname);
else
Console.WriteLine("{0} is not reachable", hostname);
Console.Read();
}

[DllImport("sensapi.dll")]
private extern static bool IsNetworkAlive(ref int flags);

[DllImport("sensapi.dll")]
private extern static bool IsDestinationReachable(string dest,IntPtr ptr);
}
}
</code>

0 new messages