First Look at the Smart Device Extension (Beta 1) for Visual Studio .NET
WirelessDevNet .com Special Contribution - by Wei Meng Lee (May 21, 2002)
Printer Friendly Version
The Smart Device Extension (SDE) package is an add-on to Visual Studio .NET that comprises of a subset of the .NET Framework known as the .NET Compact Framework. The .NET compact Framework allows developers to capitalize on their knowledge of the .NET Framework to develop mobile applications that runs on the Pocket PC and the latest Windows CE .NET operating system. In this article, I will run through the much-awaited beta 1 of the SDE and point out some of the features and pitfalls with this beta release. I will build a Windows application that runs on the Pocket PC and show how a Web service can be consumed.
Obtaining and installing the Smart Device Extension
The SDE beta 1 could now be downloaded from Microsoft’s beta site. But first you need to register and request for it. More information can be found from
The SDE beta 1 also includes the beta release of SQL Server 2000 CE Edition 2.0. I will touch on SQL Server CE in future articles. To install the SDE, you need to have Visual Studio .NET release 1 installed on your machine. I strongly recommend that you do not install the SDE on a production server as installing the SDE beta will force you to reinstall Visual Studio .NET when the SDE is finally shipped.
A quick overview of the architecture of .NET Compact Framework
The .NET Compact Framework is a subset of the .NET Framework. Programmers have the same flexibility in using the languages familiar to them as well as reusing the knowledge of the .NET Class library. However, do note that not all the classes and methods in the .NET Framework are supported in the .NET Compact Framework Class library. The following diagram shows the various layers in a typical platform.
The platform allows native applications to co-exist with .NET-based applications. The Application Domain Host (itself a native application) starts an instance of the Common Language Runtime for running managed code.
Building the sample application
I will now build a sample Pocket PC application using the Smart Device Extension (SDE) for Visual Studio .NET.
As usual, start a new project by selecting File–New-Project. Select the language you want to use
(VB.NET in my case) and the Smart Device Application template. I have named my project as PubsApp.
Next, select the platform you are targeting at. For my application, I am building a Windows application running on the Pocket PC platform.
The development environment is similar to that of developing a desktop windows application. The familiar toolbox is there, albeit with fewer controls.
I have dragged and dropped a couple of controls onto the form:
Earlier, I have also created a Web service that returns a list of titles from the Pubs database (which comes installed with SQL Server 2000). This Web service takes in a single parameter – the title of books to search, and returns the result as a Dataset. The implementation for the Web service is as shown:
Public Function getTitles(ByVal title As String) As DataSet
Dim sql As String = "SELECT * FROM titles WHERE title LIKE '%" & title & "%'"
Dim conn As New SqlConnection("server=localhost; uid=sa; password=; database=Pubs")
Dim comm As New SqlCommand(sql, conn)
Dim dataAdapter As New SqlDataAdapter(comm)
Dim ds As New DataSet()
The URL for this Web service is http://yourMachineName/TitlesWS/service1.asmx
Note that for Smart Device Extension beta 1.0, it is important to specify the machine name of the server hosting the web service, even though the Web service may be on the local machine. Specifying localhost will not work.
Back to our PubsApp application, to access the Web service, add a Web reference to the Web service just described and renamed it as TitlesWS:
When the Search button in the PubsApp application is clicked, a call is made to the Web service. The result returned by the Web service is then used to bind to the ComboxBox control:
Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
Dim ws As New TitlesWS.Service1()
Dim t As New Thread(AddressOf displayProgress)
canStopThread = False
' t.Start() ' start displaying the progress bar
ds = ws.getTitles(txtTitle.Text) ' get the web service
canStopThread = True
cboResult.DataSource = ds.Tables(0)
cboResult.DisplayMember = "title"
When the Web service is called, a thread that calls the displayProgress() subroutine is started. The subroutine will display the progress using the ProgressBar control. Note that the thread is aborted by checking the global variable canStopthread. The .NET Compact Framework does not support the Thread.Abort() method. Hence you need to explicitly control the abortion of a thread via a global variable. I will talk more about threading in the .NET Compact Framework in future articles.
Public Sub displayProgress()
'---displays the progress bar every half a second
Dim counter As Integer = 0
While Not canStopThread
'ProgressBar1.Value = counter
txtTitle.Text += counter.ToString
counter += 1
At press time, I was not able to get this thread to work correctly with the .NET Compact Framework beta 1. Hence the t.start() method was commented out.
And finally, when the user selects the item in the ComboBox control, the title, price and notes of the selected book will be displayed. The codes for displaying the details is as shown:
Private Sub cboResult_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cboResult.SelectedIndexChanged
lblTitle.Text = ds.Tables("titles").Rows(cboResult.SelectedIndex).Item("title")
lblPrice.Text = ds.Tables("titles").Rows(cboResult.SelectedIndex).Item("price")
txtNotes.Text = ds.Tables("titles").Rows(cboResult.SelectedIndex).Item("notes")
Testing the Application
You have two options for testing the application that you have just built:
Using an emulator
Using a real device
Using an emulator is perhaps the easiest way to test your application. To test your application using an emulator, select the Pocket PC Emulator option at the toolbar on top of the IDE.
Pressing F5 will launch the Pocket PC Emulator automatically. From experience, I noticed that this does not always work. The emulator may be launched but the application does not appear on the emulator. To remedy this, select Tools – Connect to Device… to manually connect to the device.
If the connection is successful, you will see a “Device Connected” message on the status bar at the bottom of the IDE:
If your computer is not connected to the network, it is essential that you install the Microsoft TCP Loopback Adapter.
When the application is tested on the emulator for the first time, the SDE will copy the files for .NET Compact Framework to the emulator:
Up to this point, if everything goes on fine, you should be able to see your application on your emulator:
Testing your application on real devices is almost the same as using an emulator. In this case, I have managed to get my application to run on my Pocket PC 2002 using ActiveSync 3.5 (via USB connection).
Some debugging tips
Here are some debugging tips that I have gathered while playing with the SDE beta 1.
Once the emulator is launched, leave it on even if you stop the current application and make modifications to it. This will avoid launching the emulator again, which is a CPU intensive task.
If the emulator is closed and the current application is run again, the emulator will be launched again, but your application won’t run. The error reported is “Sharing violation”. To remedy this, you have to manually connect to the emulator and bring it up before you run your application. Alternatively, perform a “soft reset” on your emulator.
In most cases, either doing a “soft reset” or “hard reset” on the emulator can resolve problems with the emulator. The “hard reset” option will erase the .NET Compact Framework files installed and the next time your application runs, the .NET Copact Framework files would be copied again.
When adding a Web reference, use the machine name of the server hosting the web service. If the Web service is located locally, specifying localhost will not work.
Ensure that your computer is on the network; else install the Microsoft TCP loopback adapter.
I must say I am impressed with the beta copy of the SDE. The greatest benefit for developers would be the similarity with the desktop version of the .NET Framework. If you have invested time in learning the .NET framework, developing mobile applications on the .NET Compact Framework is a breeze. Of course there are bound to be some differences between the two frameworks, but the similarity is sufficient to get most programmers up to speed quickly. As in all beta releases, expect to have some frustrations getting things right. The emulator seems quirky at times, but overall the product looks great! I can’t wait to get the final release.
Wei Meng Lee is a developer and author specializing in Microsoft .NET technologies. He is a contributing author to Visual Studio magazine, .NET magazine, XML Magazine and is the co-author of several books on WAP, XML and .NET. When not writing (codes or books), Wei Meng teaches at the School of Information and Communications Technology, NgeeAnn Polytechnic, SINGAPORE. Contact Wei Meng at email@example.com.
Entire article copyright (c)2002 Wei Meng Lee - All Rights Reserved. Reproduction or retransmition of the article in part or in whole without the permission of the author and the WirelessDevNet is prohibited.
Does your company have a solution, news, event, or scoop that WDN should know about?
Send details to firstname.lastname@example.org