Sunday, August 19, 2007

Continuing yesterday's theme on Web Services on Devices.  I thought, I'd have a go at a Compact Framework version. The first thing we need is a web-server running under Windows Mobile/CE.    Windows CE ships with a web server component,  but I figured for experimentation what I require is a simple managed code Web Server that lets me deliver content from a .Net Compact Framework application hence giving me a foundation to host web-services.

My web server needs to be fast, solid and capable of being easily extended.    What I didn't need to worry about too much was coping with heavy loading as I envisage its just going to be used 'occasionally' by a small number of clients.

So by adapting the socket server sample that ship with the .Net MicroFramework I was able to produce the following multi-threaded light weight web server.   Here's it in action  -

image

The base web-server I envision being used for all sorts of applications so I wanted to make things fairly generic.   I've implemented the code to handle the pages as follows -

public class OurResponder:IResponder
    {
        public string Responder(string method,string page,string querystring,string fullquery,string ip)
        {
            String s = "<html><head><title>Little Web Server</title></head>" +
             "<body><bold><a href=\"http://www.binaryrefinery.com/\">Learn More About The Little Web Server Here...</a></bold></body></html>";
            return s;
        }
    }

So to add extra pages and functionality all you need to-do is extend this simple method.

 

Ok, I could bother running through all the code,  however I'm going to cut to the chase and give you the application so far.

The C# solution is here -

Full Source

If you run the application it will listen on port 8000, so typing http://127.0.0.1:8000 into pocket Internet explorer should give you a result.   Its a console application so no UI,  but you don't really need one do you :-)

Let me know what you think.

Sunday, August 19, 2007 3:17:56 PM UTC  #    Comments [2]  |  Tracked by:
"Who would have thought..." (Backstage at MED) [Trackback]

Theme design by Jelle Druyts

Pick a theme: