Click here to Skip to main content
13,252,065 members (56,446 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 22 Oct 2012

Windows Mobile – A Simple Web Server with Extended Features

, 22 Oct 2012
Rate this:
Please Sign up or sign in to vote.
Windows Mobile - a simple web server with extended features

The attached web server offers some options to control the device or show information about it. The web server runs on the device and enables direct control or delivers information about the device.

The project enclosed default web page offers all implemented commands. The following is a list of what is currently implemented:

  • SystemInfo: Get OS version info
  • BEEP: Let the device beep
  • START: Starts a process
  • KILL: Kills a process
  • SETLED: Light/unlight/blink a LED
  • VIBRATE: Special LED case, this sets a LED which is a placeholder for the vibrate motor
  • SIP: Show/hide the Software Keyboard
  • SHOW: ShowWindow implementation (show normal, hide, minimize, etc.)
  • ENABLEWINDOW: Enable or disable a window

The Default Web Page

If you click a function (command), the output is displayed at the bottom of the example default page:

You can also call the functions directly from any web browser that has access to the devices network and get only the answer back.

In example, calling “” will give you “‘SystemInfo’ ”, ‘Microsoft Windows CE 5.2.29040′ = OK” or so.

Reflection Instead of switch() or If/ElseIf

These commands can be easily extended as the code uses reflection to look up the commands you send. This is a better approach than doing a If/ElseIf or Switch() search for known commands:

        /// <summary>
        /// here the myCommands object is queried for the recognized command
        /// </summary>
        /// <param name="sFunc">name of the command</param>
        /// <param name="sArg">arguments to the command</param>
        /// <param name="sResponse">return string of a command</param>
        /// <returns>True if existing command was found</returns>
        public static bool execCmd(string sFunc, string sArg, ref string sResponse)
            bool bRet = true;
                // Instantiate this class
                myCommands cmbn = new myCommands(sFunc, sArg);

                // Get the desired method by name: DisplayName
                //MethodInfo methodInfo = typeof(CallMethodByName).GetMethod("DisplayName");
                MethodInfo methodInfo = typeof(myCommands).GetMethod(sFunc);

                // Use the instance to call the method without arguments
                methodInfo.Invoke(cmbn, null);
                sResponse = cmbn.response;
            catch (Exception ex)
                ("Exception in execCmd for '" + sFunc + "' and '" + sArg + "' " + ex.Message); 
                bRet = false; 
            return bRet;

The myCommands class looks like this and is easy to extend:

        /// <summary>
        /// this class holds all know commands
        /// the class is queried using reflection to lookup a command
        /// </summary>
        class myCommands
            string name;
            string arg="";
            public string response="";

            public myCommands(string name, string sArg)
       = name;
                this.arg = sArg;

            /// <summary>
            /// return some System information
            /// </summary>
            public void SystemInfo()
                string sOS = System.Environment.OSVersion.ToString();                
                response = sOS;

            public void BEEP()
                beepType beep = (beepType)Enum.Parse(typeof(beepType), arg, false);

So, if you need to add an command, simply add a new function inside myCommands class using arg and response to communicate with the web server.

Code and Binary

The Visual Studio 2008 source code is written against Compact Framework 2.0. There are two projects, one is the great CompactWeb web server and the other is the webCommand project. The webCommand project includes a directory inetpub, which is deployed below the applications directory.

inetpub Directory

  • default.html

    This is the default web site containing examples for all commands. For example:

    <script language="javascript" 
    type="text/javascript" src="ahah.js"></script>
    <script language="javascript" type="text/javascript">
    //Calls the library function 'ahah' - defined in 'ahah.js' file.
    function load(filename) {
    <p>WebCommands TestPage</p>
    <ul id="SystemInfo">
     <li><a href="javascript:load
     ('ahah.html?SystemInfo');">OS Version</a></li>
  • javascript.js
    Simply loads ahah.js and implements the load function (asynchronously call (AJAX) technology).
  • ahah.js
    This JavaScript library does asynchronously call the ‘web commands’ (AJAX).

The rest of the files are included for testing. The same is valid for the server dir, which contains example files which will work on an external web server (i.e., XAMPP on windows), if cross-side scripting is allowed. The server files contain fixed IP address for the device and have to be changed if you would like to test cross-side scripting.

I insist on your fantasy, what else is possible. Some examples: get a screenshot, get extended device information, get a process list…….


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Germany Germany
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 22 Oct 2012
Article Copyright 2012 by hjgode
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid