I try to use the cell core connection manager with c# in order to force my application to browse through the WAP gateway (using its GUID) although the default connection is internet. I see that the WAP connection opens but then all actual requests go through the internet and I end up with 2 open connections. Any hint?
Windows – Connection manager in windows mobile
connectivitywindows-mobile
Related Solutions
You can determine that the connection is lost by making failed XHR requests.
The standard approach is to retry the request a few times. If it doesn't go through, alert the user to check the connection, and fail gracefully.
Sidenote: To put the entire application in an "offline" state may lead to a lot of error-prone work of handling state.. wireless connections may come and go, etc. So your best bet may be to just fail gracefully, preserve the data, and alert the user.. allowing them to eventually fix the connection problem if there is one, and to continue using your app with a fair amount of forgiveness.
Sidenote: You could check a reliable site like google for connectivity, but this may not be entirely useful as just trying to make your own request, because while Google may be available, your own application may not be, and you're still going to have to handle your own connection problem. Trying to send a ping to google would be a good way to confirm that the internet connection itself is down, so if that information is useful to you, then it might be worth the trouble.
Sidenote: Sending a Ping could be achieved in the same way that you would make any kind of two-way ajax request, but sending a ping to google, in this case, would pose some challenges. First, we'd have the same cross-domain issues that are typically encountered in making Ajax communications. One option is to set up a server-side proxy, wherein we actually ping
google (or whatever site), and return the results of the ping to the app. This is a catch-22 because if the internet connection is actually the problem, we won't be able to get to the server, and if the connection problem is only on our own domain, we won't be able to tell the difference. Other cross-domain techniques could be tried, for example, embedding an iframe in your page which points to google.com, and then polling the iframe for success/failure (examine the contents, etc). Embedding an image may not really tell us anything, because we need a useful response from the communication mechanism in order to draw a good conclusion about what's going on. So again, determining the state of the internet connection as a whole may be more trouble than it's worth. You'll have to weight these options out for your specific app.
This is not the best answer, and I hope someone has a better one, but: one thing you can do when your app is not able to reach the webservice is to use the Process class (in System.Diagnostics) to start your webservice URL in Internet Explorer (aka "shelling out").
This will cause IE to appear, and since it can't see the webservice either, it will show the Settings dialog that you need. Once you change your settings so that you can see the webservice, you just close IE and now you're back in your app (which will now be able to see the webservice).
Best Answer
You can do that by using Connection Manager. There is a .NET wrapper in OpenNetCF Smart Device Framework. Documentation here. You need to use the Connect method that connects to a specific network, using its GUid.