AddThis Social Bookmark Button

Print

Previewing the .NET Compact Framework

by Brian Jepson
05/28/2002

Microsoft recently released the Smart Device Extensions for .NET (Beta 1) to MSDN subscribers. Although I am an MSDN subscriber, at the time the extensions came out, I didn't have a smart device :-(

Technically, you don't need a smart device to play with these extensions, since they include an emulator. However, I wanted the real thing (total coverage), so I went hunting for a decent Pocket PC that runs the latest Pocket PC 2002 operating system. I was upset to find that the leading handhelds cost upwards of $500, until I came across reviews for five handhelds. Number one on that list is the Audiovox Maestro PDA-1032, a rebranded Toshiba Pocket PC e570 with half the memory. I was able to find the Maestro for $299, so I went ahead and ordered it.

After it arrived, I naturally spent some time looking for games to run on it ... the compact framework could wait. The next day, I downloaded the compact framework, and fired up Visual Studio .NET. I'm not much of a Visual Studio .NET user (I edit most of my C# using vim), but I decided I could make an exception, since Visual Studio .NET makes it very easy to work with compact framework applications.

Creating an Empty Application

To create a Pocket PC application, I did the following:

  1. At the Visual Studio Start Page, I chose "New Project."
  2. Next, I selected "Smart Device Application" from the Visual C# Projects.
  3. I chose Windows Application as the project type, and Pocket PC as the target platform. A blank form (Form1) and backing code (Form1.cs) appeared.
  4. I dropped a ComboBox on the form.
  5. Finally, I changed the name of the ComboBox to lstCommodities.

Connecting To a Web Service

At this point, I could have deployed the application to the smart device, but it would have just been a form with an empty list box. So I decided I'd plug it into a Web service that I'd been working on for a tutorial at the recent O'Reilly Emerging Tech Conference. The Web service can return a list of energy commodities and price quotes.

To hook up my application to the Web service, I did the following:

  1. Right-clicked on my project in the Solution Explorer and selected "Add Web Reference."
  2. Pasted in the WSDL for my Web service.
  3. Clicked "Add Reference."

This left me with a namespace called SmartDeviceApplication1.com.brinkster.www30 (its name is concatenation of my project namespace and the host name of the Web service) that I could import with the using statement. So I added this line to Form1.cs:


using SmartDeviceApplication1.com.brinkster.www30;

Next, I wanted to invoke the Web service and stuff the results into the combo box. That namespace that I imported is full of all sorts of goodies, including a class (CommodityFun) that exposes the Web methods, and classes (Commodity, Quote, etc) for all of the return values of the Web service. In this case, I'm interested in a list of commodities, so I need to deal with the Commodity class. Here is the code I added to my form's source code:


private void Form1_Load(object sender, System.EventArgs e)

{

  CommodityFun wsfun = new CommodityFun(); // proxy class for remote web service

  Commodity[] commodities = wsfun.ListAll(); // invoke a web service method

  foreach (Commodity c in commodities)

  {

    lstCommodities.Items.Add(c.name); // add each commodity to the combo box

  }

}

Not much to it, is there? The Web reference makes sure that my application knows about the definition of the Web service proxy class (CommodityFun) as well as classes for the return values (such as Commodity), so I can refer to them as though they were locally defined.

Deploying the Application

This was the easy part. I selected Start from the Debug menu, and Visual Studio .NET deployed everything (the compact framework and the application) to my Pocket PC. A few seconds later, the form appeared on my Pocket PC screen, and I was able to debug it from Visual Studio .NET. Figure 1 shows a screenshot (from the emulator, since I haven't figured out how to take a screenshot from my Pocket PC).


Figure 1. A simple web service client

Here's an article I found that walks you through a compact framework example with many more screenshots: "Creating Pocket PC Apps with the Smart Device Extensions".

Brian Jepson is an O'Reilly editor, programmer, and co-author of Mac OS X Panther for Unix Geeks and Learning Unix for Mac OS X Panther. He's also a volunteer system administrator and all-around geek for AS220, a non-profit arts center in Providence, Rhode Island. AS220 gives Rhode Island artists uncensored and unjuried forums for their work. These forums include galleries, performance space, and publications. Brian sees to it that technology, especially free software, supports that mission. You can follow Brian's blog here.


Return to the .NET DevCenter.