Table of Contents
BackCover
The Definitive Guide to the .NET Compact Framework
Chapter 1: The .NET Compact Framework
Understanding the .NET Compact Framework
What's Missing from NETCF?
Differences Between eVB and VB .NET
Working Between .NET and .NETCF
Using Compiler Directives
Summary
Chapter 2: Smart Device Extensions
Languages Supported by SDE
SDE Within the VS .NET IDE
Step-by-Step Tutorial: Hello World .NET
Summary
Chapter 3: Designing an Effective Interface
Pocket PC Design Standards
Larry Roof's Design Rules
Step-by-Step Tutorial: Panel-Based Interface
Windows Forms
The Code Behind a Form
Working with Forms
Working with Dialog Boxes
Step-by-Step Tutorial: Building a Custom Dialog Box
Summary
Chapter 4: NETCF Controls
The Button Control
The CheckBox Control
The ComboBox Control
The ContextMenu Control
The DataGrid Control
Step-by-Step Tutorial: Creating an Owner-Drawn Control
Creating a Component
Starting a Component
Adding Design-Time Support
Summary
Chapter 6: Menus, Toolbars, and Status Bars
Building Menus
Building Context-Sensitive Menus
Building ToolBars
Building Status Bars
Step-by-Step Tutorial: Menus and Toolbars
Summary
Chapter 7: Graphics
Some Basic Knowledge
Okay, Let's Draw Something
Step-by-Step Tutorial: Creating a New Button
Working with Images
Step-by-Step Tutorial: Displaying a Simple Image
Step-by-Step Tutorial: Scrolling an Image
Summary
Chapter 8: Files and Directories
System.IO Namespace
Managing Directories
Managing Files
Working with Files
Step-by-Step Tutorial: Building a Text File Demo
Step-by-Step Tutorial: Building a Binary File Demo
Summary
Chapter 9: Introduction to ADO .NET
System.Data Namespace
Licensing SQL Server CE
Summary
Chapter 12: Working with Server-Based Data
My Data, Get My Data
Summary
Chapter 13: Working with Device-Based Data
Covering the Database Basics
Remote Data Access
Step-by-Step Tutorial: Beyond Anonymous
Merge Replication
RDA or Replication, That Is the Question
Summary
Chapter 14: Working with XML
Basic XML
Step-by-Step Tutorial: Creating a Configuration Reader
DOM Navigation of Your Documents
Working with XML Data Using a DataSet
Looking at Data Schemas
Using XML Serialization
Summary
Chapter 15: Mobile Networking
Working with the HTTP Protocol
Working with the TCP Objects
Step-by-Step Tutorial: Working with TCP
Working with the IrDA Objects
Step-by-Step Tutorial: Working with IrDA
Summary
Chapter 16: XML Web Services
Understanding XML Web Services
Web Service Limitations with NETCF
Developing the Foundation
Working with Settings in an INI File
Working with Settings in an XML File
Working with Settings in the Registry
Summary
Chapter 21: Creating Setups for Your Applications
Setup Fundamentals
Building Cab Files
Step-by-Step Tutorial: Examining a Basic Cab Build
Step-by-Step Tutorial: Building a Custom Installation
A Note on Testing Setups
Summary
Chapter 22: Producing Reports
Producing HTML Reports
Examining the HTML Reporting Sample
The HTMLViewer Alternative Approach
Summary of Producing HTML Reports
Producing Printed Reports
Producing Printed Reports with PrinterCE.NetCF
Working with the PrinterCE Object
Summary of Printing with PrinterCE.NetCF
Printing Reports with the Mobile Printing Toolkit
Summary of Printing with the Mobile Printing Toolkit
Pocket PC Report Generation with Report CE
Summary of Printing with Report CE
Summary of Printing with Report CE
Summary
Appendix A: Setting Up Your Development Environment - A Quick Step-Through
Install Visual Studio .NET 2003
Install ActiveSync
Summary
Index
Index_B
Index_C
Index_D
Index_E
Index_F
Index_G
Index_H
Index_I-J
Index_K
Index_L
Index_M
Index_N
Index_O
Index_P
Index_Q
Index_Q
Index_R
Index_S
Index_T
Index_U
Index_V
Index_W
Index_X-Y
Index_Z
List of Figures
List of Tables
List of Code Examples
List of Sidebars
Chapter 22 - Producing Reports
Appendix A - Setting Up Your Development Environment—A Quick Step-Through
Appendix B - Working with the Emulator
Appendix C - Resources
Appendix D - Sample Applications
Appendix E - Error Handling
Appendix F - Custom Controls in C#
Index
List of Figures
List of Tables
List of Code Examples
List of Sidebars
Back Cover
The .NET Compact Framework brings the world of managed code and XML Web services to smart devices, and it
enables the execution of secure, downloadable applications on devices such as personal digital assistants (PDAs),
mobile phones, and set-top boxes.
The Definitive Guide to the .NET Compact Framework targets both first-time and experienced mobile developers,
and is a comprehensive guide to building mobile applications using the .NET Compact Framework (CF) and Smart
Device Extensions (SDE) for Visual Studio .NET. Expert authors Larry Roof and Dan Fergus provide developers with
everything they need to produce robust applications, including how to create effective user interfaces, work with
device-based data sources, access enterprise data, leverage Web services, incorporate XML into applications, build
help systems, and generate setup routines.
About the Authors
Dan Fergus currently works as a consultant and trainer teaching a Compact Framework course along with Visual
Basic .NET and ASP.NET courses. Dan has been working with .NET and the Compact Framework since the
beginning, and currently has several applications on the PocketPC on the market. Before becoming an independent
contractor, Dan worked at NuMega Technologies as the development lead on Visual Basic 6 debugging tools. Dan
also speaks at developer conferences around the world and writes for several magazines.
Larry Roof has been a key individual in the Windows CE market from the beginning. He authored the first book on
developing mobile applications with Visual Basic for Windows CE, is a frequent speaker at major technical
neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly
or indirectly by the information contained in this work.
The source code for this book is available to readers at in the Downloads section. You will need to answer questions pertaining to
this book in order to successfully download the code.
To Carol, my love, my life. I would not be here without you.
—Larry Roof
To Susie and the boys.
Thanks for putting up with the late nights and the times when I came home
tired after traveling, or staying up too late working on this book. I love you.
—Dan Fergus
About the Authors
Larry Roof has long been considered an expert in the field of mobile application development. He is a frequent speaker at leading conferences
including Microsoft TechEd, the Windows CE Developer's Conference, and the Visual Basic Insider's Technical Conference. He has written for a number
of industry-leading magazines and has a monthly MSDN Voices column called "Two for the Road."
Larry heads up one of the premier mobile solution development companies. His company specializes in creating integrated mobile solutions that extend
enterprise environments.
In addition to writing and consulting, Larry offers training in both face-to-face and video-based formats. He has been recognized by Microsoft as an
eMbedded Most Valuable Professional (eMVP) for his contributions to the mobile development community.
You can contact Larry at and can obtain more information about the consulting and training services offered by his company at
.
It's been a long time since that first computer course in COBOL back in 1973. But instead of getting a degree, Dan Fergus got a little side-tracked and
spent the next 12 years as an EMT and paramedic in Hillsborough County, Florida.
spent the next 12 years as an EMT and paramedic in Hillsborough County, Florida.
After Dan hung up his scissors, he went back to school at the University of South Florida and received a B.S. in biology and a B.S. in chemical
engineering. While working as an engineer and living in Japan for two years as a technical liaison for a chemical company, Dan picked up a copy of
Turbo C while on a trip to Taiwan for $5, just to keep up his programming skills.
When that job ended, Dan started out on his own and worked as a consultant in the Dallas/Fort Worth area for several years before going to work for
NuMega Technologies. While there, Dan was the lead developer for CodeReview and FailSafe, both Visual Basic debugging products. Dan's last
position at Compuware (formally NuMega) was that of a technical evangelist, spending 2 years doing nothing but working, learning, teaching, and writing
about .NET.
Now, take that basic scenario and extrapolate it to mobile application development. The Pocket PC becomes the bag with its limited space. The .NET
Framework becomes the item you want to take with you. While you would like to take the whole .NET Framework, it won't fit on the Pocket PC. Enter the
.NET Compact Framework, or simply NETCF. It's a subset of the .NET Framework, comprised of just the items that you need to "survive" as a mobile
developer. It's a perfect match for the limited space on a Pocket PC.
If you look at the .NET Compact Framework in this light, you'll understand why Microsoft did what they did. While the .NET Compact Framework tops out
at a rotund 30 megabytes in size, NETCF is a diminutive 1.5 megabyte. In Disney terms, the .NET Framework is Dumbo, and NETCF is Tinkerbell. Now,
it doesn't take a rocket scientist to understand shrinking a framework by a factor of 20-to-1 is going to require that a few things be left out. I'll be honest
with you; I'm amazed that NETCF has any functionality at all given the pruning it endured.
So if you're Microsoft, how do you go from 30MB to 1.5MB? For starters, you don't take two knives. In NETCF terms, that is to say you don't include two
ways to do the same thing. Microsoft trimmed namespaces. They trimmed methods. They trimmed the number of overloads for each method. They
removed functionality that would less likely be useful in developing mobile applications.
What does all this mean to you? That it's unlikely you'll be able to take your .NET experience as it exists today and use it to create mobile applications
without experiencing some frustration, heartaches, and despair. You're going to have to adjust your programming style some. You probably will have to
learn new ways to do things you already know how to do. You may have to seek therapy.
I'm going to make a prediction. Somewhere along the line, you're going to ask, "Why for the love of all things good did Microsoft leave out that feature?"
Trust me, it'll happen. The simple answer is they're just messing with you. Okay, that's not the reason, but it'll probably seem that way. The real reason is
that Microsoft made some tough decisions. There were a number of useful, powerful, very cool features and functions that had to be trimmed. For the
most part though, they've left an alternative for everything they removed. It might not be the alternative you would like, and it very likely will take a bit more
coding, but it's an alternative. In some cases, they haven't provided an alternative. For the most part, these totally abandoned features were either too big
in size or considered to be of marginal use to mobile developers.
Understanding the .NET Compact Framework
Microsoft developed the .NET Compact Framework with one intention in mind: to build applications. By applications, I don't mean drivers, COM
components, ActiveX controls, Today screen plug-ins, or anything else that might get you called geek by other kids on the tech playground. I'm talking
about applications that display, gather, process, and forward information. You know, those applications that give users a reason to carry a device. While
they typically will have an interface, they don't have to have one. The data that they are working with might be local, remote, or some combination of the
two.
The .NET Compact Framework simplifies application development on smart devices. A smart device is Microsoft's generic category name for any
device that has, well, smarts. Currently this includes the Pocket PC, Pocket PC 2002, Pocket PC Phone Edition, Smartphone, and other devices running
Windows CE .NET 4.1 or later.
Note
Note For more on leveraging external functions and subroutines from your mobile applications, see Chapter 17.
.NET Compact Framework Class Library
The .NET Compact Framework class library is a collection of reusable classes that tightly integrate with the common language runtime. Your applications
leverage these libraries to derive functionality.
As you would expect from an object-oriented class library, the .NET Compact Framework types enable you to accomplish a range of common
programming tasks, including interface design, leveraging XML, database access, thread management, and file I/O.
The following sections describe the common functionality available through NETCF.
Form-Related Classes
NETCF implements a subset of the System.Windows.Forms and System.Drawing classes, which allow you to construct rich Windows CE–based
user interfaces for your device applications. Much of the interaction with these classes is managed for you by the form designer component of Smart
Device Extensions operating within Visual Studio .NET.
The implementation of WinForms under the .NET Compact Framework includes support for forms, most controls found in the .NET Framework, hosting
third-party controls, bitmaps, and menus. Table 1-1 lists the controls included with the .NET Compact Framework.
Table 1-1: NETCF Controls
CONTROL DESCRIPTION
Button Simple command button
CheckBox Common check box
ComboBox Drop-down list of times
ContextMenu Context-sensitive menu for association with another object
DataGrid Grid that can be bound to a data source
DomainUpDown Control that provides a list of items the user can navigate using scroll bars
HScrollBar Horizontal scroll bar
ImageList Container used to store images, which in turn will be used with other controls such as the ToolBar, ListView, and TreeView
InputPanel Controls the Soft Input Panel (SIP) on Windows CE devices
Label Simple control that allows you to display text
ListBox Control that provides a list of items from which the user can pick
ListView Control that provides four views for displaying data: large icon, small icon, list, and details
MainMenu Control that implements a menu with a form
NumericUpDown Numeric input field that allows both manual entry as well as scroll bars
OpenFileDialog Interfaces with the standard Windows CE Open File dialog box
Visual Basic Support
Visual Basic .NET makes liberal use of helper functions that are located in a VB Helper library. The .NET Compact Framework includes a subset of these
functions as well. These functions are considered by VB developers to be a core part of the language, which is the reason for their inclusion.
If you're an existing eVB developer converting over to NETCF, what this means is that many of the VB language functions you are used to working with
If you're an existing eVB developer converting over to NETCF, what this means is that many of the VB language functions you are used to working with
will be available to you in Visual Basic .NET.
GDI Support
The .NET Compact Framework provides support for the basic GDI drawing elements including bitmaps, brushes, fonts, icons, and pens through the
System.Drawing namespace.
Base Classes
The .NET Compact Framework provides a robust set of base classes that expose a wide range of functionality for use by developers. This underlying
infrastructure enables you to write rich .NET applications by allowing you to create multithreaded applications (System.Threading), leverage networking
resources (System.Net), and work with files (System.IO).
IrDA Support
Windows CE devices, such as the Pocket PC and Pocket PC 2002, include infrared (IR) communication capabilities. In support of this, the .NET
Compact Framework includes classes that allow you to leverage IR communication from within your application. These classes are part of the
System.Net.IrDA namespace. You can use IR to communicate to Pocket PCs, printers, and other IR-enabled devices.
Note For more information on working with IR, see Chapter 15.
Bluetooth Support
The .NET Compact Framework doesn't natively provide support for Bluetooth. You can access most third-party Pocket PC implementations of Bluetooth
via either serial port communications or through a provider's API.
A La Carte Features
To conserve resources on the target device, Microsoft divided the .NET Compact Framework into logical components. By delivering components as
separate DLLs, or as they are referred to within the .NET Compact Framework, assemblies, Microsoft gives you the option of picking and choosing the
features you need, and only those features that your target device has the space to hold.
An example of this is the System.SR assembly, which contains error message strings. Including this assembly with your application allows access to
detailed descriptions of any errors encountered, which is certainly helpful during a fitful debugging session (like there is any other type of debugging
session). Excluding this assembly doesn't affect the performance or functionality of your application; it simply means you won't have access to detailed
error messages.
Tip Generally speaking, you will only want to include the System.SR assembly while developing your applications.
Imports statements in a module. The one rule is that you must place all Imports statements before anything else in a code module, including Module or
Class statements.
The syntax for the Imports statement is
Imports [aliasname = ] namespace
The aliasname is optional, providing an alternative way to reference the namespace from within your code. Figure 1-4 provides an example of the use of
the Imports statement with an aliasname. In this case, vb has the equivalent value of Microsoft.VisualBasic.
Figure 1-4: Adding an Imports statement
Figure 1-4: Adding an Imports statement
How far you shorten the naming of an element affects how you reference its uniquely named members. For example, if only the namespace is specified,
as shown in Figure 1-5, all of the uniquely named members, along with the members of modules within that namespace, are available without having to
fully qualify their names. In this example, the Imports statement shortens the naming of members within the Microsoft.VisualBasic namespace.
Figure 1-5: An Imports statement that specifies only the namespace
Listing 1-1 demonstrates ways you could subsequently reference the Strings module. Any of the options, from fully qualified to abbreviated, provide
exactly the same functionality.
Listing 1-1: Working with the Strings Module
Imports vb = Microsoft.VisualBasic
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim mb As MessageBox
mb.Show(Microsoft.VisualBasic.Strings.Left("abcdef", 3))
mb.Show(vb.Strings.Left("abcdef", 3))
mb.Show(Strings.Left("abcdef", 3))
End Sub
End Class
As you extend the reference defined by the Imports statement, only the members of that further restricted element are available without qualification. For
NETCF.
Nonessential Controls
At first, you're led to believe that the list of missing controls is but a few. In fact, the controls that are missing are nearly as many as are included. Now, is
that areason for you to abandon programming with the .NET Compact Framework? Certainly not. Like other missing features, it provides you with an
opportunity to demonstrate your programming prowess. How's that for a positive spin.
Table 1-2 lists .NET Framework controls that didn't make it into NETCF. The absence of most of these controls is not going to be of any significance to
mobile developers. Since printing has such a limited role in mobile applications, removing the whole family of print-related controls is not an issue. That
takes care of the CrystalReportViewer, PageSetupDialog, PrintDialog, PrintDocument, PrintPreviewControl, and PrintPreviewDialog controls. You can
replace many of the missing dialog boxes with your own dialog boxes (see Chapter 3) or by accessing system dialog boxes directly using the Windows
CE API (see Chapter 17).
Table 1-2: Controls Missing from NETCF
CONTROL DESCRIPTION
CheckedListBox Hybrid list box that includes check boxes next to each item; a suitable workaround for this limitation is the ListView control.
ColorDialog Control that provides access to the operating system's color dialog box.
CrystalReportViewer
Control that links an application to Crystal Reports. No precanned reporting functionality is provided under NETCF, nor for
that matter is printing supported.
DateTimePicker Graphic component for selecting date and time.
ErrorProvider Graphical indicator to the user as to what fields on a form contain invalid values.
FolderBrowserDialog Interface to folder hierarchies.
FontDialog Control that provides access to the operating system's font dialog box.
GroupBox Control used to group related controls together. The Panel control offers a suitable replacement.
HelpProvider Control that links an application to a help file.
LinkLabel Control that combines the functionality of a label with a hyperlink.
MonthCalendar Pop-up calendar from which the user could select a date.
NotifyIcon Control that adds a link between a status bar icon and background applications.
PageSetupDialog Control used to manipulate page, margin, and printing configurations for a document.
PrintDialog Control that provides access to the operating system's print dialog box.
PrintDocument Object used to define a print document.
PrintPreviewControl Preview of how a printed document will appear.
Note
There is already a third party that provides the necessary framework for working with Pocket Access databases. For more on this topic, see
Appendix C.
Absence of File Notifications
While NETCF offers a solid subset of input and output functionality, in my opinion it's missing one key component—notifications on changes made to
files. This functionality would allow mobile applications to be informed when a file changes, such as when updates are delivered to a device.
Binary Serialization
Both the BinaryFormatter and SoapFormatter classes are absent from the .NET Compact Framework, severely limiting serializing and deserializing
objects.
Access to the Windows Registry
The .NET Framework has the Microsoft.Win32.Registry namespace, which makes it easy to work with the Windows registry from an application.
Obviously, this namespace was not included in NETCF, as it has to do with Win32, not Windows CE. Unfortunately, no Windows CE equivalent of this
namespace was included in NETCF. As a result, you're forced to turn to the Windows API if your application requires access to the Windows CE registry.
Note For more information on accessing the Windows CE registry, see Chapter 17.
Leveraging COM Components
The absence of the COM interop is one of the most loudly debated and complained about limitations of NETCF. This is particularly true for developers
who are switching over from eMbedded Visual Basic, where they were accustomed to leveraging COM objects, including ActiveX controls, to extend their
development capabilities.
Incorporating COM objects into a NETCF application is a painful two-step process. First, you must write an unmanaged (read eVC++) DLL wrapper that
exposes the COM object. Depending upon the complexity of the COM object, this may be anything from a simple to a life-altering challenge. Second, you
must use PInvoke to access your DLL wrapper. Luckily, the development community has already begun work on accessing the more commonly used
COM components.
Note For more on accessing DLLs from your mobile applications, see Chapter 17.
Security
The .NET Compact Framework doesn't secure access to unmanaged code. Any application can call any system or nonsystem API.
There is no role-based security with the .NET Compact Framework. The principal object has no understanding of known identity or known role.
Web Services
The most notable exclusion from the .NET Compact Framework Web service capabilities is the inability to use cookies. Cookies are widely used to
maintain state on the server between calls from a client. While the use of cookies in Web services is not as prevalent as their use on Web sites, they are
still in use.
Decimal 16 Decimal number
Double 8 Double-precision floating point number
Integer 4 32-bit signed integer
Long 8 64-bit signed integer
Object 4 Capable of storing any data type
Short 2 16-bit signed integer
Single 4 Single-precision floating point number
String n/a Series of Unicode characters
Declaring Values While Dimensioning a Variable
Visual Basic .NET allows you to declare the value of a variable at the time you are dimensioning the variable. For example:
Dim intFactor As Integer = 5
Fixed-Length Strings Are Not Supported
Visual Basic .NET doesn't support fixed-length strings. For example, the following eMbedded Visual Basic statement would result in a compilation error
under Visual Basic .NET.
Dim strDemo As String*50
Use Zero-Bound Arrays
eMbedded Visual Basic allowed you to specify the lower and upper bounds for an array. In Visual Basic .NET, you must use zero for the lower bound.
Language Structure Changes
While both eVB and VB .NET are based upon the Visual Basic languages, there are some noticeable differences.
Default Properties
With eMbedded Visual Basic, you could use default properties. When you referenced an object without specifying a property, it would be resolved to the
default property for the specific object. For example, the following lines of code operate identically under eMbedded Visual Basic:
Text1 = "something"
Text1.Text = "something"
Visual Basic .NET in comparison doesn't implement default properties for its controls. In all instances, you must specify the desired property.
Subroutines and Functions Require Parentheses
Under Visual Basic .NET, all calls to subroutines or functions require the use of parentheses. For example, the eMbedded Visual Basic code
MsgBox "test "
will need to be written in Visual Basic .NET as
MsgBox ("test ")
Try
cn = New System.Data.SqlServerce.SqlCeConnection("Data Source= " & _
"\My Documents\NorthwindDemo.sdf")
' Configure the command.
cmd = New System.Data.SqlServerCE.SqlCeCommand("SELECT * FROM Customers", cn)
' Create the DataAdapter and fill the DataSet.
da = New System.Data.SqlServerCE.SqlCeDataAdapter(cmd)
da.Fill(ds)
' Make some changes to the DataSet here.
' Save the DataSet.
da.Update(ds)
Catch ex As Exception
' Handle errors here.
End Try
This example starts by declaring the four variables, which will hold instances of the SqlCeConnection, SqlCeCommand, SqlCeDataAdapter, and
DataSet objects. These instances allow us to connect to and retrieve data from a local SQL Server CE database.
The SqlCeConnection object establishes a connection to a SQL Server CE database. The SqlCeCommand object defines the command used to
retrieve the desired data from the source. In this case, it's all of the records from the Customers Table. The SqlCeDataAdapter acts as the conduit
retrieve the desired data from the source. In this case, it's all of the records from the Customers Table. The SqlCeDataAdapter acts as the conduit
between the SQL Server CE database and our DataSet. The SqlCeDataAdapter Fill method loads the DataSet. Later in this example, the
SqlCeDataAdapter Update method saves the DataSet.
As this example demonstrates, you can expect a steep learning curve if you're coming from eMbedded Visual Basic and ADOCE to VB .NET and ADO
.NET. Simply stated, everything has changed in the way of dealing with data.
What Are DataSets?
Developers experienced with ADO are accustomed to working with recordsets. The ADO .NET equivalent to a recordset is the DataSet. A DataSet is
a disconnected cache that developers can use within their applications. It is essentially an in-memory database (IMDB). It offers a relational view of
the database query stored in XML format. Through DataSets, developers can access table, row, and column data. Since DataSets are disconnected,
they inherently support a scalable model, since the client application doesn't maintain a database connection for the entire time that the application
runs. DataSets can be shuttled between desktop .NET and NETCF. The SQL Data Connector accesses the database to populate a DataSet. You
can work with DataSets programmatically, or bind them to controls, such as text boxes, list boxes, and grids.
XML Functionality Included Under NETCF
XML is the universal format for data on the Internet. XML allows developers to easily describe and deliver rich, structured data between applications,
varied data sources, and different operating systems in a standard, consistent way.
varied data sources, and different operating systems in a standard, consistent way.
While eMbedded Visual Basic offered low-level support for XML, the .NET Compact Framework provides Visual Basic .NET with a set of tools that make
it simple and straightforward to work with XML structures.
As with other components of the .NET Compact Framework, the XML-related classes offer a subset of the functionality found in the .NET Framework. The
support for XML in the .NET Compact Framework
Adheres to the SOAP standards and provides access to SOAP headers
Allows developers to create applications that consume DataSets from and post DataSets to Web services
Enables developers to read an XML document, manipulate the document, post the document to a server, and maintain the document on the
device
The .NET Compact Framework provides support for the following XML functionality:
XML Reader— Provides a forward-only, read-only stream of parsed XML tokens
XML Writer— Provides a forward-only, write-only method for generating well-formed XML documents
XML Document— Provides access to the XML Document Object Model (DOM)
Working with Web Services
One of the most powerful new features of Visual Basic .NET is the ability to create applications that access, or consume, a Web service. Web services,
running on standard Internet Web servers, expose methods you can call from your Visual Basic .NET–based applications. Developing a Web service
client with Visual Basic .NET is simple. It involves adding a reference to the Web service, creating an instance of the Web service, and then calling the
methods provided by the Web service. HTTP/S GET/POST (non-SOAP) Web services can also be called but require additional coding. You will need to
parse the XML yourself since serialization is not available.
Note For more on Web services and creating a Web service client, see Chapter 16.
Local Data Storage Using XML
The XML support provided by the .NET Compact Framework, and accessible from Visual Studio .NET, allows developers to keep a persistent XML
stream in a serialized manner to a local text file. This provides developers with an alternative to relational databases and standard files as a method of
storing data.
Developers can use this technique to store configuration information, as well as for offline caching of small, simple data volumes. This method provides a
simple yet effective alternative for situations in which a full-functioned relational database is not required.
The following shows a simple example of reading and writing a DataSet to a file as XML. As you can see, there's really nothing to it.
best a challenge.
There are namespaces within NETCF that are not part of the .NET Framework.
That said, code compiled under the .NET Framework will run under the .NET Compact Framework, as is, as long as it only makes use of functionality
found in NETCF. The opposite doesn't hold true though. Code compiled under the .NET Framework will not run under the .NET Compact Framework. The
reason for this one-way support is that, while compiled assemblies of both platforms contain the same IL code, the library assemblies for the two
platforms are different. In addition, while the assembly loader for the .NET Compact Framework is smart enough to handle these differences, the .NET
Framework loader is not.
How NETCF handles this is that the assembly loader maps references to the .NET Framework library assemblies to the appropriate NETCF assemblies.
Pretty slick, although I'm not sure that this is something that I'm just dying to be able to do.
In my mind, what is more of an issue is the question of reusing code. Can you write modules for use with both desktop and device applications? The
simple answer to this question is yes, with the added qualifier of "if you're careful and have some foresight."
In creating code for use under both .NET and NETCF, you must be selective as to what parts and features of the framework each includes. The way I like
to look at this is to "write for the least common denominator," which is almost always NETCF. Another way to look at this is to say that if a piece of code
runs under NETCF, it will very likely run under the .NET Framework.