[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Changing APN on the go in WM5

Posted on 2011-04-29
10
Medium Priority
?
932 Views
Last Modified: 2013-12-21
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
Comment
Question by:Bojerne
  • 5
  • 5
10 Comments
 
LVL 3

Expert Comment

by:efatihan
ID: 35492064
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
 
LVL 1

Author Comment

by:Bojerne
ID: 35492289
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
 
LVL 1

Author Comment

by:Bojerne
ID: 35492631
It gives me error related to "private string GPRSConfigXML =" saying "Keyword is not valid as identifier" ?

Please advice
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
LVL 3

Expert Comment

by:efatihan
ID: 35496913
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
 
LVL 3

Expert Comment

by:efatihan
ID: 35496921
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
 
LVL 1

Author Comment

by:Bojerne
ID: 35497175
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
 
LVL 3

Expert Comment

by:efatihan
ID: 35498276
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
 
LVL 1

Author Comment

by:Bojerne
ID: 35498406
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
 
LVL 3

Accepted Solution

by:
efatihan earned 2000 total points
ID: 35498466
have you seen this page,

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

it might be usefull,
0
 
LVL 1

Author Comment

by:Bojerne
ID: 35499533
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

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator (https://www.appcelerator.com/). This article presumes a wor…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question