Broadcasting technical support to Windows Mobile\CE Application Developers to help realizing their potential

Programmatically retrieve the GPRS’ APN configured for a Mobile Operator (XPath on Windows Mobile)

Programmatically retrieve the GPRS’ APN configured for a Mobile Operator (XPath on Windows Mobile)

  • Comments 0

This was a good exercise as it showed how powerful XPath queries are, this time for XML Provisioning... Basically what the developer was interested on was the GPRSInfoAccessPointName of the CM_GPRSEntries Configuration Service Provider. The XML Provisioning Query was:

<wap-provisioningdoc>
    <characteristic-query type="CM_GPRSEntries" />
</wap-provisioningdoc>
Once you have the desired query-xml, you can programmatically run it from within a NETCF v2.0 application by using the ConfigurationManager.ProcessConfiguration method (ConfigurationManager is a class of the Microsoft.WindowsMobile.Configuration namespace, defined in the Microsoft.WindowsMobile.Configuration.dll assembly).

The code is:

XmlDocument configDoc = new XmlDocument();
configDoc.LoadXml(
    "<wap-provisioningdoc>" +
    "<characteristic-query type=\"CM_GPRSEntries\" />" +
    "</wap-provisioningdoc>");
XmlDocument output = ConfigurationManager.ProcessConfiguration(configDoc, true);
Now that you have a XmlDocument, you can use a XPath string to search the value you want: you can look at the resulting xmloutput of the RapiConfig in order to find the correct XPath string, which in this particular case is:
/wap-provisioningdoc/characteristic/characteristic[@type="<INSERT GPRS ENTRY HERE>"]/characteristic/parm[@name="GPRSInfoAccessPointName"]

I recommend using RapiConfig precisely in order to verify what’s the GPRS ENTRY name is configured in your case, otherwise the application may not work. In my testings I tried with a GPRS operator of mine (“TIM”). In NETCF, you can run a XPath query by using the .SelectSingleNode() or .SelectNodes() methods of the class XmlDocument:

XmlNode aux = output.SelectSingleNode(
    "/wap-provisioningdoc/characteristic/characteristic[@type=\"" + 
    OperatorSettingToBeSearched + 
    "\"]/characteristic/parm[@name=\"GPRSInfoAccessPointName\"]");
 

In conclusion, the sample code you may customize is (this was a NETCF v2.0 Console application):

static string OperatorSettingToBeSearched = "TIM";
static void Main(string[] args)
{
    XmlDocument configDoc = new XmlDocument();
    configDoc.LoadXml(
        "<wap-provisioningdoc>" +
            "<characteristic-query type=\"CM_GPRSEntries\" />" +
        "</wap-provisioningdoc>");
    XmlDocument output = ConfigurationManager.ProcessConfiguration(configDoc, true);
    XmlNode aux = output.SelectSingleNode("/wap-provisioningdoc/characteristic/characteristic[@type=\"" +
        OperatorSettingToBeSearched + 
        "\"]/characteristic/parm[@name=\"GPRSInfoAccessPointName\"]");
    MessageBox.Show(aux.Attributes["value"].Value);
}
Leave a Comment
  • Please add 2 and 1 and type the answer here:
  • Post