views:

138

answers:

1

I have a .NET application (WPF but that doesn't really matter) running on Windows 7 (x86). I want to connect to the internet from my application to call a web service. When there is a wifi connection, I want to use that. If there is no wifi connection, I want to automatically connect to a GPRS connection setting defined in the OS (e.g. in internet explorer's connection settings).

In the days of dial-up, you could specify both a LAN connection and a dial-up connection in IE, and when IE detected that there was no LAN, you were asked if you wanted to connect to dial-up.

In this case, I have wifi instead of LAN and GPRS instead of dialup and I'm not using IE but a custom .NET application. Prompting the user with an OS dialog would be OK.

I can do this myself with the managed wlan API (codeplex) and the GPRS chipset manufaturer's SDK, but I want to know if there is a way that Windows 7 can do this for me.

+2  A: 

Use DefaultWebproxy available on a WebRequest. The DefaultWebProxy property reads proxy settings from the app.config file. If there is no config file, the current user's Internet Explorer (IE) proxy settings are used.

For Ex-

webRequest.Credentials = CredentialCache.DefaultCredentials;
                    if (WebRequest.DefaultWebProxy != null)
                    {
                        webRequest.Proxy = WebRequest.DefaultWebProxy;
                        webRequest.Credentials = CredentialCache.DefaultCredentials;
                        webRequest.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
                    }
                    else
                    {
                        Trace.WriteLine("Unable to detect proxy.");
                    }

Check out these links -

  1. http://msdn.microsoft.com/en-us/library/5t9y35bd.aspx
  2. http://msdn.microsoft.com/en-us/library/system.net.webrequest.defaultwebproxy.aspx
  3. http://msdn.microsoft.com/en-us/magazine/cc300743.aspx
Vinay B R
@Vinay B R - I don't see how using a proxy will start up GPRS if there is no WLAN conneciton. Can you clarify a bit more?
StephaneT
@StephaneT - I have only answered the reading IE connection settings from .net part. Is your actual question about selecting one of 2 available networks.
Vinay B R
What I mean is that if you define a connection in IE, not a LAN connection but a dial-up or other connection, is it possible to detect that there is no LAN connection and activate one of the other connections without having to implement this yourself. In other words, is there a windows or IE api that I can call that does this for me.
StephaneT