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]

Tuesday, September 11, 2007 1:25:20 AM UTC
hey Richard that looks great. just what im looking for.
i just cant get it to work tho :(
I open up ur project and run it using my WM 6 emulators (ive tried a few),
and typing http://127.0.0.1:8000/ in IE on the device gives me nothing.

It actually gives me that 'cant connect' balloon dialogue, and asks me to go into the network settings page.

when using break points, the program never passes this line -> Socket clientSocket = server.Accept();

anything im missing??
Thanks.

Dan
Tuesday, September 11, 2007 5:51:28 AM UTC
You should see in visual studio in the debug output some messages namely a 'listening on xxxxxxx'. That should be the url to type into pocket IE. The other thing that I find helps, is to cradle the emulator (launch device emulator manager from the tools menu in visual studio and select the emulator you are using and then right click and 'cradle'.

If your still having trouble have a look at the web-service on devices download, I improved the ickle web-server between the two posts.

Let me know how you get on.
Richard
Comments are closed.

Theme design by Jelle Druyts

Pick a theme: