title: Creating persistent RAS connection with opennetcf Ras in Windows CE 6.0
body: <p>I'm in need to create an GPRS connection in an PDA that has windows ce 6. Now normally i would had to use the manufacturer's dll to create that, but they said that they use ras to accomplish this. The only problem of using that is that i program in .net c#, and the library is an unmanaged code one. </p>
  
  <p>Fortunately i came by the opennetcf ras library that does already the necessary pInvokes for the windows ras library, the only problem being the poor documentation.</p>
  
  <p>I created then an library that would call and set-up the necessary GPRS connection on windows. I'm using an Portuguese telecom operator that uses the following definitions:</p>
  
  <pre><code>Operator Name: Optimus P
  Apn:  umts
  Password: *******
  User: ******
  </code></pre>
  
  <p>Consulting the gsm module definition, i had the following modem settings:</p>
  
  <pre><code>Connection Name: GPRS
  Device: Hayes Compatible on COM1:
  Baund Rate:115200
  Data Bits: 8
  Parity:1
  Stop Bits: 1
  Flow Control: Hardware
  </code></pre>
  
  <p>and of course the extra settings (or how i call it the atCall)</p>
  
  <pre><code>+cgdcont=1, "ip", "umts"
  </code></pre>
  
  <p>This settings when i use the control panel and do an connect with that profile, it connects and i'm able to call all the webservices without an error. It also shows an extra profile for the modem that shows the settings for the device, incluid the ipaddress, subnet mask and even the default gateway.</p>
  
  <p>The problem is that when i use the library that i created to create an gprs connection programatically, and then call the webservices at some point it throws me an web exception : The remote name could not be resolved. I also checked and the extra icon does not appear, but if i see the GPRS status it appears as it is connected.</p>
  
  <p>The code that create, destroys and query if it exists an connection is as follows:</p>
  
  <pre><code>using System;
  using System.Linq;
  using System.Collections.Generic;
  using System.Text;
  using OpenNETCF.Net;
  using OpenNETCF.Diagnostics;
  
  namespace gsmAdapterNet
  {
  /// &lt;summary&gt;
  /// GPRS Connection class
  /// &lt;/summary&gt;
  public class GPRS
  {
      private static string connectionName = "GPRS";
  
  
      /// &lt;summary&gt;
      /// Connects the GPRS.
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static bool ConnectGPRS()
      {
  
              //precisamos de obter as connecoes e ligar
  
              RasEntryCollection connecoesPossiveis = Ras.Entries;
              RasEntry _currentEntry = connecoesPossiveis[connectionName];
              _currentEntry.RasStatus += new RasNotificationHandler(RasStatusHandler);
              RasError resultado = _currentEntry.Dial(false);
              if (resultado == RasError.Success)
                  return true;
              else
                  return false;
  
  
      }
  
      static void RasStatusHandler(int hConn, RasConnState State, RasError ErrorCode)
      {
          Logger.WriteLine("");
          Logger.WriteLine("RAS STATUS: " + ErrorCode.ToString() + " , State: " + State.ToString());
      }
  
  
      /// &lt;summary&gt;
      /// Disconnects the GPRS.
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static void DisconnectGPRS()
      {
          RasEntryCollection entradas = Ras.Entries;
          foreach (RasEntry possivelEntrada in entradas)
          {
              if (possivelEntrada.Name == connectionName)
              {
                  possivelEntrada.Hangup();
              }
          }
  
  
      }
  
      /// &lt;summary&gt;
      /// Determines whether this instance is connected.
      /// &lt;/summary&gt;
      /// &lt;returns&gt;
      ///     &lt;c&gt;true&lt;/c&gt; if this instance is connected; otherwise, &lt;c&gt;false&lt;/c&gt;.
      /// &lt;/returns&gt;
      public static bool isConnected()
      {
  
          RasConnection[] conecoes = Ras.ActiveConnections;
          foreach (RasConnection conecao in conecoes)
          {
              if (conecao.Name == connectionName)
                  return true;
          }
          return false;
  
      }
  
      /// &lt;summary&gt;
      /// Dumps the ras entries.
      /// &lt;/summary&gt;
      public static void DumpRasEntries()
      {
          foreach (RasEntry entry in Ras.Entries)
          {
              Logger.DumpRasEntry(entry);
          }
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So resuming the question is how i can create an viable connection with the opennetcf ras library </p>
  
  <p>Best Greetings</p>