Connecting to internet via RAS

  • Thread starter Stephan Oetzel [flowOffice]
  • Start date
S

Stephan Oetzel [flowOffice]

Hello @ll,

I've written a .NET Compact Framework application for a Windows CE 4.21
device. This application uses a webservice to communicate with the server.
The device has a GPRS modem on board and a Dial-In-Connection is defined. In
Internet Explorer this works very well, I can connect to Internet by calling
a website's url and it automatically opens up the dial-in window. How can I
connect from my application automatically to the internet?

Best reguards,
Stephan
 
M

ManniAT

Hi Stephan,

when you call a WS in .NET CF the connection is made automaticly if possible.
So when your IE connects by itself - your app should do it also.

BUT - you have no control about hanging up (CF does not hang up!!).
So for us it works better to do it ourself by:
a.) check for a network connection - if found call the WS - and you are done ELSE
b.) pinvoke the ConMGR to connect to the internet
---or even easier - use OpenNETCF
c.) call you webservice
d.) hang up if you want

Manfred
 
S

Stephan Oetzel [flowOffice]

Hello Manfred,

could you just give me some code, how to connect to the internet and check
for network connection?

Best reguards,
Stephan
 
M

ManniAT

Hello Sthephan,

here is some code to detect a network connection - it is "assembled" from some working parts of code -- but I think it should run.

It has some "informational MessageBoxes" in it.
private bool IsNetConnected() {
try {
string strHostName = Dns.GetHostName();
MessageBox.Show(strHostName);
IPHostEntry ihE = Dns.GetHostByName(strHostName);
IPAddress ipFound=null;
IPAddress ipLH=IPAddress.Parse("127.0.0.1");
foreach (IPAddress ipA in ihE.AddressList) {
if (ipA.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && ipFound == null) { //avoid V6 adresses
ipFound = ipA; //only the first non V6 is collected - normaly a "break" would follow -- removed to get the msgboxes
//break; //we found what we were searching for
}

MessageBox.Show(ipA.AddressFamily.ToString() + "\n" + ipA.ToString() + "\n" + ipA.Equals(ipLH).ToString() + "\n" + (ipLH ==
ipA ? "Gleich" : "Anders"));
}
if(ipFound!=null && !ipFound.Equals(ipLH)) {
return(true); //found a V4 other than localhost
}
return/(false);
//here the short way (no check for V6 addresses - just check if the first address is LocalHost -- no need for the loops!!
// string strIPAdr = ihE.AddressList[0].ToString();
// return (strIPAdr != IPAddress.Parse("127.0.0.1").ToString());
}
catch {
return (false);
}
}

The question for "AddressFamily" is neede on PPC 2003 - becaue you can find IP.V6 adresses there, so the first address in this case
will not be 127.0.0.1.
For the connection manager - it is a little more code and interop - so I thing the best is to take a look at OpenNetCF for this.

HTH

Manfred
 
S

Stephan Oetzel [flowOffice]

Hello Manni,

Well, this code is OK, but unfortunately I'm not working on Pocket PC but on
Windows CE 4.20. I just need to know, how I dial a Dial-Up-Connection that
is configured in Windows CE.

Any tips?

Best reguards,
Stephan
 
G

Guest

Hello,

you have to use Ras API. You have Ras dll examples here:

http://www.codeppc.com/evc/index.htm

Regards

ACP


Stephan Oetzel said:
Hello Manni,

Well, this code is OK, but unfortunately I'm not working on Pocket PC but on
Windows CE 4.20. I just need to know, how I dial a Dial-Up-Connection that
is configured in Windows CE.

Any tips?

Best reguards,
Stephan


ManniAT said:
Hello Sthephan,

here is some code to detect a network connection - it is "assembled" from
some working parts of code -- but I think it should run.

It has some "informational MessageBoxes" in it.
private bool IsNetConnected() {
try {
string strHostName = Dns.GetHostName();
MessageBox.Show(strHostName);
IPHostEntry ihE = Dns.GetHostByName(strHostName);
IPAddress ipFound=null;
IPAddress ipLH=IPAddress.Parse("127.0.0.1");
foreach (IPAddress ipA in ihE.AddressList) {
if (ipA.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork
&& ipFound == null) { //avoid V6 adresses
ipFound = ipA; //only the first non V6 is collected - normaly a
"break" would follow -- removed to get the msgboxes
//break; //we found what we were searching for
}

MessageBox.Show(ipA.AddressFamily.ToString() + "\n" + ipA.ToString() +
"\n" + ipA.Equals(ipLH).ToString() + "\n" + (ipLH == ipA ? "Gleich" :
"Anders"));
}
if(ipFound!=null && !ipFound.Equals(ipLH)) {
return(true); //found a V4 other than localhost
}
return/(false);
//here the short way (no check for V6 addresses - just check if the first
address is LocalHost -- no need for the loops!!
// string strIPAdr = ihE.AddressList[0].ToString();
// return (strIPAdr != IPAddress.Parse("127.0.0.1").ToString());
}
catch {
return (false);
}
}

The question for "AddressFamily" is neede on PPC 2003 - becaue you can
find IP.V6 adresses there, so the first address in this case will not be
127.0.0.1.
For the connection manager - it is a little more code and interop - so I
thing the best is to take a look at OpenNetCF for this.

HTH

Manfred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top