Search code examples
c#compact-frameworkgprs

Activate GPRS connection on compact framework (c#)


I'm developing an app in C# (.NET3.5 Compact Framework) and I need to connect to a sql server occasionally over GPRS. However the connection closes after some time of inactivity or if the PDA is placed on the craddle.

I'm looking for a way to check and re-enable the connection automatically from the app.

I've seen several pages on the web suggesting using the ConnectionManager, the Opennet.CF framework or an approach based on a XML doc. None provide a full example.

My latest test is based on the code below.

Could you help me with some suggestion or piece of code?

Many thanks in advance,

Filipe

public static void setCM_ProxyEntriesHTTP(Guid Guid)
    {
        try
        {
            remCM_ProxyEntries(getCM_ProxyEntriesAtual());
            string wWap = "<wap-provisioningdoc>" +
            "<characteristic type=\"CM_ProxyEntries\">" +
            "<characteristic type=\"HTTP-{" + Guid.ToString() + "}\">" +
            "<parm name=\"ExtraInfo\" value=\"\" />" +
            "<parm name=\"Override\" value=\"\" />" +
            "<parm name=\"Username\" value=\"\" />" +
            "<parm name=\"Enable\" value=\"1\" />" +
            "<parm name=\"Type\" value=\"0\" />" +
            "<parm name=\"DestId\" value=\"{436EF144-B4FB-4863-A041-8F905A62C572}\" />" +
            "<parm name=\"SrcId\" value=\"{" + Guid.ToString() + "}\" />" +
            "</characteristic>" +
            "</characteristic>" +
            "</wap-provisioningdoc>";
            ConfigWrapper.ProcessXml(wWap);
        }
        catch { }
    }

Solution

  • Thank you josef! :)

    I was able to check and connect using the following code:

     private static bool InternetAvailable2()
        {
            bool hasNet = false;
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://www.bing.com");
                request.Method = "GET";
                request.Accept = "text/html, application/xhtml+xml, */*";
                request.Proxy = null;
                //request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        hasNet = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"NetAvail2");
            }
        }