• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 978
  • Last Modified:

Changing APN on the go in WM5

I have a small application in vb.net compact framework running on a WM5 device, which uses the Sub shown below to force a gprs connection - and that works fine :) But I need some sort of method to enable me to change the apn on the fly - depending on what server I'm going to connect to.

Please advice

    Friend Sub HttpWebRequest()
        Try
            Dim GPRSconn As New OpenNETCF.Net.ConnectionManager
            GPRSconn.Connect()
        Catch ex As System.Net.WebException
            Main.HandleException(ex)
        End Try
    End Sub

I've seen a solution similar to what I'm looking for in the link below, but can't figure out how to implement it

http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/dd31827c-ebdc-48c4-a091-725a1d79c83b/
0
Mik Mak
Asked:
Mik Mak
  • 5
  • 5
1 Solution
 
efatihanCommented:
hello,

it is easy to change the apn settings. Assuming you have the following xml,

private string GPRSConfigXML =
            "<wap-provisioningdoc>" +
                "<characteristic type=\"CM_GPRSEntries\">" +
                    "<characteristic type=\"{0}\">" +
                        "<parm name=\"DestId\" value=\"{{{4}}}\" />" +
                        "<parm name=\"UserName\" value=\"{1}\" />" +
                        "<parm name=\"Password\" value=\"{2}\" />" +
                        "<parm name=\"Domain\" value=\"\" />" +
                        "<parm name=\"AlwaysOn\" value=\"1\"/>" +
                        "<characteristic type=\"DevSpecificCellular\">" +
                            "<parm name=\"GPRSInfoValid\" value=\"1\" />" +
                            "<parm name=\"GPRSInfoAccessPointName\" value=\"{3}\" />" +
                        "</characteristic>" +
                    "</characteristic>" +
                "</characteristic>" +
            "</wap-provisioningdoc>";
       
then you call the following method,

string s = string.Format(
                    GPRSConfigXML,
                    GPRSConnectionName,
                    APNUserName,
                    APNPassword,
                    GPRSInfoAccessPointName,
                    "436EF144-B4FB-4863-A041-8F905A62C572"
                );
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(s);
                XmlDocument x = ConfigurationManager.ProcessConfiguration(xDoc, false);

the configurationmanager is under the Microsoft.WindowsMobile.Configuration namespace.
after you do that, it is up to you to decide which apn settings to use depending on the server.
0
 
Mik MakConsultantAuthor Commented:
Hi Efatihan

Thank you for your extremely fast answer ;) - I'll try and test it later. what references do I need to make it work ? And how can I see what DestID to use ?

Thanks
Mikael
0
 
Mik MakConsultantAuthor Commented:
It gives me error related to "private string GPRSConfigXML =" saying "Keyword is not valid as identifier" ?

Please advice
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
efatihanCommented:
as far as i remember dest id was an id in registry that i found long time ago. it worked for me in many devices.

for your error, i can tell you that this line may be wrong

"<parm name=\"DestId\" value=\"{{{4}}}\" />" +
it might be like this,

"<parm name=\"DestId\" value=\"{{4}}\" />" +
0
 
efatihanCommented:
one more thing,

the resulting xml should be like this, vb.net might not like the above syntax, so change it accordingly,

<wap-provisioningdoc>
                <characteristic type="CM_GPRSEntries">
                    <characteristic type="{0}">
                        <parm name="DestId" value="{{4}}" />
                        <parm name="UserName" value="{1}" />
                        <parm name="Password" value="{2}" />
                        <parm name="Domain" value="" />
                        <parm name="AlwaysOn" value="1"/>
                        <characteristic type="DevSpecificCellular">
                           <parm name="GPRSInfoValid" value="1" />
                           <parm name="GPRSInfoAccessPointName" value="{3}" />
                        </characteristic>
                    </characteristic>
                </characteristic>
            </wap-provisioningdoc>
0
 
Mik MakConsultantAuthor Commented:
Hi Efatihan

Dont think your code was in vb.net :), but from you code I made the code below which creates the connection profiles ok, but I'm not able to "overwrite" in order to "switch" between different APN's ?

    Friend Sub CreateAPN(ByVal GPRSConnectionName As String, ByVal APNUserName As String, ByVal APNPassword As String, ByVal APNName As String, ByVal DestID As String)
        Dim d As System.Xml.XmlDocument = New System.Xml.XmlDocument()
        Dim GPRSConfigXML As String = "<wap-provisioningdoc>"
        GPRSConfigXML += "<characteristic type='CM_GPRSEntries'>"
        GPRSConfigXML += "<characteristic type='" & GPRSConnectionName & "'>"
        GPRSConfigXML += "<parm name='DestId' value='{" & DestID & "}' />"
        GPRSConfigXML += "<parm name='UserName' value='" & APNUserName & "' />"
        GPRSConfigXML += "<parm name='Password' value='" & APNPassword & "' />"
        GPRSConfigXML += "<parm name='Domain' value='' />"
        GPRSConfigXML += "<parm name='AlwaysOn' value='1'/>"
        GPRSConfigXML += "<characteristic type='DevSpecificCellular'>"
        GPRSConfigXML += "<parm name='GPRSInfoValid' value='1' />"
        GPRSConfigXML += "<parm name='GPRSInfoAccessPointName' value='" & APNName & "' />"
        GPRSConfigXML += "</characteristic>"
        GPRSConfigXML += "</characteristic>"
        GPRSConfigXML += "</characteristic>"
        GPRSConfigXML += "</wap-provisioningdoc>"
        GPRSConfigXML = GPRSConfigXML.Replace("'", Chr(34))
        'MsgBox("GPRSConfigXML = " & GPRSConfigXML)

        Try
            d.LoadXml(GPRSConfigXML)
            Dim d2 As System.Xml.XmlDocument = Microsoft.WindowsMobile.Configuration.ConfigurationManager.ProcessConfiguration(d, False)
            'MsgBox("d2 = " & d2.InnerXml)
        Catch ex As Exception
            Main.HandleException(ex)
        End Try
    End Sub
0
 
efatihanCommented:
actually, the code i sent creates new "default" apn. have you tried to initialize the new apn before connecting to different servers? i mean how often do you need to change the apn? if it is not always (for performance issues), i can tell you that you create new apn.
0
 
Mik MakConsultantAuthor Commented:
I need to change the apn to connect to different servers on different company networks - probably at least once a day, so need some sort of mechanism to change between 2 apn's. I've also tried some code to disable a gprs profile, and also some code to delete the gprs profile - but cannot make it work properly :)  If you have any ideas to solve this, I would be most thankfull :)

Please advice
Thanks
Mikael
0
 
efatihanCommented:
have you seen this page,

http://msdn.microsoft.com/en-us/library/ms890704.aspx

it might be usefull,
0
 
Mik MakConsultantAuthor Commented:
Yes, and I've tried the examples from this page

http://msdn.microsoft.com/en-us/library/ms834710.aspx

I have no problem creating the gprs profiles, but are having problems switching between them
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now