|
Part I: Smartphone and .NET 1
Chapter 1: Introduction to Microsoft Smartphone 3
What Is a Smartphone? 3
Smartphone Applications and Services 4
Mobile Commerce 5
Mobile Enterprise 5
Mobile Data Service and Entertainment 6
Challenges of Smartphone Application Development 6
Introducing Microsoft Windows Mobile 7
Windows Mobile 5.0 7
Microsoft Smartphone from a User’s Perspective 8
Summary 10
Chapter 2: .NET Compact Framework Fundamentals 11
Introducing the Microsoft .NET Framework 11
The Common Language Runtime 12
.NET Framework Class Libraries 13
Visual Studio 2005 14
Introducing the .NET Compact Framework 15
CLR of the .NET Compact Framework 15
.NET Compact Framework Class Libraries 15
Platform Invoke 16
Smartphone Development Tools 17
.NET Compact Framework Type System 18
Types 19
Attributes and Reflection 21
Generics 21
Exception Handling 21
xii
Contents
A Quick Review of C# 22
Value Types 23
Reference Types 24
Operators 25
string and object 26
Classes and Interfaces 28
Polymorphism 32
Arrays and Collections 33
Summary 35
Part II: Smartphone Application Development 37
Chapter 3: Developing Your First Smartphone Application 39
Required Tools 39
Visual Studio 2005 40
Windows Mobile 5.0 SDK for Smartphone 41
Smartphone Device Emulator 41
ActiveSync 42
All-In-One Package 43
Building Your First Smartphone Application 43
Creating a Smartphone Project 43
Adding Code to the Form 49
Project Files 51
Testing and Debugging Applications 52
Packaging and Deploying Applications 56
Packaging Applications 56
Signing Applications 59
Delivering and Installing Applications 61
Summary 62
Chapter 4: User Interface and Input 63
UI Design with Forms and Controls 63
Supported Controls 64
Control Behaviors 65
Smartphone UI Design 85
Soft Keys 86
The Home and Back Keys 86
General UI Flow of Smartphone Applications 87
Creating an Application with Multiple Forms 88
xiii
Contents
Keyboard Input and Input Mode 96
Input Mode 96
Soft Key Functionality 101
Additional UI Considerations 102
Auto-Save 102
DPI and QVGA Issues 102
Performance 103
Summary 103
Chapter 5: Data Storage and File I/O 105
Overview of Smartphone Data Storage 105
The System.IO Namespace 107
Creating a File Directory Browser 113
Implementing a Memo Application 120
Summary 129
Chapter 6: Data Access with SQL Server Mobile 131
ADO.NET Overview 132
Microsoft SQL Server 2005 Mobile Edition 134
SQL Server Mobile Architecture 135
Installing SQL Server Mobile 136
Setting Up the SQL Server Mobile Server Environment 138
Installing SQL Server Mobile Tools 138
Creating a Database and Tables from SQL Server 2005 138
Creating a Publication 142
Configuring Web Synchronization 145
Creating a SQL Server Mobile Database 147
Creating Subscriptions in SQL Server Mobile 148
Writing SQL Server Mobile Applications 151
A Simple Application with the DataGrid Control 151
The SqlServerCe Namespace 157
Summary 163
Chapter 7: Networking 165
An Overview of Smartphone Networking 165
Emulator Networking 166
Web Access 167
The HttpWebRequest and HttpWebResponse Classes 168
Creating HTTP Request 169
xiv
Contents
TCP Servers and Clients 176
The IPEndPoint Class 176
The IPAddress and IPHostEntry Classes 176
Network and Host Byte Order Conversion 177
The TcpListener and TcpClient Classes 178
An Example of TcpListener and TcpClient 180
Network Sockets 187
TCP Sockets 188
UDP Sockets 196
Nonblocking Mode and Asynchronous Methods 198
Summary 199
Chapter 8: E-mail, SMS, and PIM Data 201
Pocket Outlook Object Model (POOM) 201
The WindowsMobile.PocketOutlook Namespace 203
Creating E-mail Applications with Managed APIs 205
Creating a Simple E-mail Application 208
Creating an E-mail Application with Attachments 210
Accessing PIM Data 216
Using SMS 220
Summary 226
Chapter 9: XML and Web Services 227
Overview of XML and Web Services 227
XML Support in .NET Compact Framework 229
XML Syntax 229
An XML Example: Customizing the Home Screen 231
XML Schema 233
XML-Related Classes 234
XmlDocument and XmlTextReader 235
XmlNodeReader and DataSet 240
An XML Processing Sample Application 242
Building a Smartphone XML Web Service Application 248
Adding a Web Reference 248
Consuming Web Services 249
Summary 253
Chapter 10: Platform Invoke 255
Managed and Unmanaged Code 255
Building Unmanaged DLLs 257
xv
Contents
Using P/Invoke in the .NET Compact Framework 260
Declaring and Calling an Unmanaged Code Function 261
Error Handling 262
Marshaling Data 263
An Example of a P/Invoke Application 271
Optimizing P/Invoke Performance 278
Summary 279
Chapter 11: Exception Handling and Debugging 281
Exceptions and Exception Handling 281
Exceptions 282
The try...catch Statement 282
The finally Statement 283
The throw Statement 285
Exception Stack Trace 286
The Exception Class 288
The SystemException Class 289
The ApplicationException Class 290
Best Practices of Exception Handling 292
Debugging in Visual Studio 2005 293
Debugging Windows 293
Debugging Setting 294
Deploying and Debugging in Visual Studio 294
Defining Symbols 294
Limitations of Debugging 295
Multithreaded Debugging 296
Managed Threads 296
Race Condition 298
Deadlock 300
Summary 304
Part III: Advanced Topics 305
Chapter 12: Device and Application Security 307
Mobile Threats 307
Glossary of Terms 309
Digital Signatures, Certificates, and Application Signing 309
Privileged and Unprivileged Applications and Certificate Stores 310
xvi
Contents
Trusted and Normal Applications 310
Security Policies and Roles 311
Windows Mobile 5.0 Security Models 312
Certificate Management in Windows Mobile 5.0 314
Obtaining Certificates 314
Signing Applications with Certificates 315
Managing Certificates 319
Security Policies 322
An Example Code 325
Perimeter Security 330
Physical Access Control 330
Antivirus Considerations 331
Summary 332
Chapter 13: Data and Communication Security 333
Data Protection 334
Data Encryption 334
Database Encryption and Password Protection 341
Securing Communication Channels 346
Network Authentication 346
Secure Sockets Layer (SSL) 347
Virtual Private Networks 350
Wi-Fi 353
Securing Web Services with SOAP Headers 353
Server Side 354
Client Side 360
Summary 362
Chapter 14: Globalization and Localization 363
Globalization and Localization Support 363
Culture 364
The CultureInfo Class 365
Developing a World-Ready Application 366
Creating Localized Resources 366
A Sample Application with a Localized Satellite Assembly 370
Localizing Data 377
Dates, Time, and Calendars 377
Numbers and Currency 379
Strings 381
xvii
Contents
Best Practices 382
Summary 383
Chapter 15: Graphics 385
.NET Compact Framework Graphics 386
The Graphics Class 386
Creating a Graphics Object 387
The Color, Pen, and Brush Objects 387
Vector Graphics 389
Drawing Text 397
Working with Fonts 399
Drawing Images 400
Drawing Bitmaps 402
Embedded Resources 408
Summary 409
Chapter 16: Performance 411
General Principles 411
Using .NET Compact Framework Performance Counters 412
CLR Performance 417
Garbage Collection 417
Call Overhead 418
Math 423
Reflection 423
Generics 423
Class Library Guidelines 424
BCL Collections 424
StringBuilder versus String 426
Regular Expression 427
XML and Data Access 428
XMLReader and XMLWriter 428
XML Schema 428
XML Serialization 429
Data Access 429
Windows Forms 430
Form Loading Performance 430
Form Layout 431
BeginUpdate and EndUpdate 433
Summary 434
xviii
Contents
Appendix A: New Features in .NET Compact Framework 2.0 437
Appendix B: A Glance at the .NET Compact Framework 2.0 Class Library 441
Appendix C: The Smartphone Bootstrapping Process 459
Index 465 |
|