Adding AJAX Support to Windows Mobile Applications


Web applications designed for browsers on desktop
computers have already for a long time used scripts to
create more usable user interfaces. Add AJAX support on top
of this, and you are getting close to the rich set of
features available in traditional desktop applications.
However, the world is getting more and more mobile, and
users start to utilize your web applications from their
mobile phones.

Because the browsers available in mobile phones have been
previously quite limited, using advanced scripting
functionality has been difficult. However, Microsoft’s Windows Mobile platform includes the Pocket
or Mobile Internet Explorer browser (usually abbreviated PIE
or WMIE), and the most recent versions of this browser
support AJAX. AJAX support has been available in a limited
way already since Windows Mobile 5.0, and the later 6.0
versions already contain nice support for AJAX applications.
This brings many possibilities for application

In this article, you are going to learn how you can use
Visual Studio 2008 (Windows Mobile development is not
currently available in the beta releases of Visual Studio
2010) and C# to develop a simple AJAX-enabled web
application that works on a Windows Mobile Professional 6.0
phone or later. For testing purposes, you are going to learn
how to use a phone emulator. This makes at least initial
testing easier, as you don’t need to have a real phone right

Getting ready to develop web applications for WM 6.0

When Visual Studio 2008 became available a few years ago,
Windows Mobile 5 was the main mobile platform that the tool
supported out of the box. This means that if you are
interested in developing applications for Windows Mobile
6.0, you would need to separately download the Windows
Mobile 6.0 SDK package, and install it on top of Visual
Studio 2008 SP1.

The SP1 (Service Pack 1) for Visual Studio is also
required to test the code shown in this article. For
information on where to download both Visual Studio 2008 SP1
and the Windows Mobile 6.0 SDK, see the Links section at the
end of this article.

Figure 1. The Windows Mobile 6.0 SDK can be freely downloaded from Microsoft’s web pages

Installing both the Mobile SDK and the SP1 for Visual
Studio is straightforward, although installing especially
the SP1 can take a long time. Even on a fast computer, it
can take an hour or more to get both installed. However, the
process is highly automatic, and your intervention is
basically needed only to launch the installation process or
log in after a reboot.

Once the installation is complete, you can start Visual
Studio (you will need to close it to install the updates)
and create a new project for your web application. Since the
focus of this article is on adding AJAX functionality to
ASP.NET web applications, you do not need to start a Visual
Studio Smart Device (Windows Mobile) project, but instead a
regular web project.

For the purposes of this article, you will see how you
can use ASP.NET MVC for web application development, but you
are free to use the more traditional WebForms model just as
well. Even so, the new MVC model contains good support for
AJAX, and if you haven’t already investigated this new
technology, it is a good time to start. Remember that
ASP.NET MVC is not a native part of Visual Studio 2008, and
thus you will need to separately download a small
installation package for it, too.

Creating a simple MVC application skeleton

To get started with development, create or open an
ASP.NET MVC project. Then, add a new controller class to the
Controllers folder in the project, and give it an
appropriate name, such as
MobileAJAXController“. The name of the
controller indicates that it will handle requests for the
relative path /mobileAJAX. This information becomes handy

Since you need to be sure a Windows Mobile phone can
connect to your ASP.NET MVC application, it’s best to
initially create a very simple controller action method to
serve content to the mobile phone. ASP.NET MVC supports, in
the simplest scenario, action methods that return plain
strings. You could then add the following method for testing
purposes. You can later on improve it to do some real

public string Hello()
return “Hello, World!”;

If you want, you can test that your MVC application works
as expected by hitting the F5 key in Visual Studio (or by
choosing the Start Debugging command from the menu) and
testing the controller action you just added in your
computer’s browser. The address should be something like
http://localhost:1234/mobileAJAX/hello. The
port number will change dynamically, but Visual Studio will
automatically launch your browser with the correct URL.

If your tests succeed, the next step would be to make
sure the application is running on a real web server, namely
IIS. IIS is required so that you can really test the
application on a mobile phone; the development web server
that comes with Visual Studio will not allow network
connection from outside localhost.

Because of this limitation, you will need to find a
server running IIS (preferably a Windows Server 2008 system
with IIS 7.0 or 7.5, as these versions contain best support
for ASP.NET MVC applications).

Figure 2. IIS must be properly configured to test mobile applications, even with the emulator

This article will not focus on setting up IIS for MVC
applications, but you can find detailed instructions from
the MVC documentation. The following sections assume that
you have IIS installed, and that you can access the
application with an URL such as:


Of course, your real URL will vary, so be sure to adjust
the URL accordingly when testing.

More by Author

Must Read