Marcus Perryman Microsoft The Mobile Architect Marcus Perryman Microsoft
Agenda Common Patterns and Designs Architecting Mobile Applications Synchronization Web Services SQL CE MSMQ Performance Deployment
Common Patterns and Designs Document tested simple mechanisms Provide common terminology for architects and developers Promote Re-use Flexibility Cohesion Patterns and practices Documents best practices for whatever – MVC, Visitor pattern etc GOF
Defining SOA Service-Oriented Architecture is an approach to organizing information technology in which data, logic, and infrastructure resources are accessed by routing messages between network interfaces Basic value proposition is to provide consistent, stable interfaces in front of diverse or volatile implementations Establish context for information exchange across organizations Encapsulate complexity within organizations Enable context-sensitive information processing Organising data and logic Message based not object based SOA is static whilst backend can change Based on sending messages between components – chunky not chatty
Microsoft’s Vision for SOA Service orientation will encapsulate and componentize processes and systems Help manage complexity Permit controlled change Support continuous improvement Business capabilities and business processes will be modeled as services Organizations will expose touchpoints into these processes to both internal and extra-organizational actors Allows automation of processes that have defied automation until now On the path to the Agile Enterprise
Three Tier Pattern Presentation Layer Business Layer Data Access Layer Order Entry Web Pages Reporting Web Pages Business Layer Order Management Reporting Management User Management Data Access Layer ADO.NET Order Data Access Reporting Data Access
Service Orientated Architecture Security Presentation Layer Order Entry Web Pages Reporting Web Pages Business Layer Service Interfaces Order Management Reporting Management User Management Can extend a traditional 3 tier app so that other front ends could be added to the application Data Access Layer ADO.NET Order Data Access Reporting Data Access Services
Mobile Architectures Need to address Communication From device to server or device Security Are communications secure? Is data secured? Performance Deployment All of the above can impact physical and logical Designs
Server Applications Supports large number of devices ASP.NET Mobile Web Pages HTML for Pocket IE WML for WAP Browsers Supports large number of devices Low cost deployment Centralized logic Online only Browser user interface Will see some demonstrations of this later in the day
Client Applications Targets a Smartclient Deployment required Server Web Services MSMQ HTTP Channel Targets a Smartclient Deployment required Can work disconnected Rich user interface Outlook is a good example of a smart client application
Online / Offline Smartclient applications need to support online / offline Synchronization Options One / Both ways Application / Database level Need to ensure that an application still responds when the network is unavailable
Synchronization Consider your applications requirements Both Ways Multi-user updates of data Web Services SQL CE Replication One Way Mutually exclusive data MSMQ SQL CE Remote Data Access SMS Can intercept SMS messages using a COM component to tell the device something has happened – such as a webservice being moved to another URL
Synchronization Application Application Sync Data Sync User Interface Application Logic Data Access Layer Business Layer Web Services UI Application Sync Data Sync SQL Server CE Two types of sync – app sync or low level data sync Application Sync Data Sync High reuse of logic Slower synchronization Fast synchronization Low level of logic Data collisions
Web Services Synchronous Asynchronous Security Good for small, quick packets of data Block the current thread Asynchronous Good for larger packets of data Callback when processing finished Check for exceptions due to connectivity issues Security Recommended to use SSL Digest or Clear Text authentication Currently no support for WSE Custom via SOAP headers Product group are looking at the future roadmap of WSE, currently there is a user sample on GotDotNet that shows how to do some WSE stuff (WS:Security)
Web Services Considerations Store and Forward Web service requests cached Executed when network available Variable re-try algorithm Data Compression GSM data costs Conserve bandwidth
Smart connected architecture SmartClient Application WebRequestCompleted Custom WS Proxy Asynchronous Timed Event Network Test Order Service Store and Forward The proxy is running on the client and can be used to ensure that webservice calls are potentially stored & forwarded etc Store Map Service Web Service
Data Compression Server side Client side Windows 2003 Server Enable compression and gzip.dll via MMC Modify metabase adding asmx to HcScriptFileExtensions for gzip and deflate compression filters Client side Need to override GetWebRequest and GetWebResponse .NET Compact Framework SP1 Client applications need some additional coding to be able to exploit. Data compression on the server side requires WS 2003 Link that documents these changes later in the presentation On client override methods – only works in .NET CF V1 SP1 Extra code on the client to call GZip.Deflate – no inbuilt support, thrid party free library (on the CD)
Client Data Compression public class GzipProxy : SoapHttpClientProtocol { protected override WebRequest GetWebRequest(System.Uri uri) WebRequest req = base.GetWebRequest(uri); req.Headers.Add("Accept-Encoding", "gzip, deflate"); return req; } protected override WebResponse GetWebResponse(WebRequest req) return new CompressedHttpWebResponse(req); On the way out we say that we can accept compressed results On the way back in, we need to unzip it using the CompressedHttpWebResponse class (again available on the CD)
SQL Server CE 2.0 Runs on Pocket PC 2000+ Smartphone version coming 1.5MB memory footprint Compact Framework Support Authentication and Encryption Connectivity Remote Data Access - SQL7/2000 Merge Synchronization – SQL2000 Can call SQLCE from eVB, CF and natively Single user
Database Feature Set Rich functionality for small footprint Multi-column indexes Referential integrity Sub-selects (IN) Defaults Inner/outer joins One file database Null support Unicode support Transactions Data-types Real, Numeric, NVarChar, NText, Image, Integer, DateTime, VarBinary, UniqueIdentifier, Money Having/group by Seek on index Set functions Identity attribute Local security - DB encryption (128bit) and database password No stored procedures
CE Data Access Storage Architecture Enterprise Backend Oracle / db2 / etc .NET CF / Managed Stack XML/BizTalk/CS 2002 VS .NET (VB.NET, C#) Native/Unmanaged Stack eVB 3.0 eVC 3.0 ADO.NET Ethernet SQL Server CE Data Provider SQL Server Client Data Provider TDS ADO CE v3.1 Well Connected CLR / .NET CF OLEDB CE OLEDB / Replication API 802.11b, CDPD, GSM, CDMA, TDMA, etc. SQL CE Edition v2.0 Data Provider Backend stuff can talk to SQL Server. PPC can use TDS directly to go to SQL 2000. Need to have a good network connection for this, and this uses the SQL Server client data provider SQL CE provider talks to SQL CE (local) database Can also replicate data over HTTP – need to add in some stuff on the server to enable this. Server Agent sits inside IIS and talks up to SQL Server Client Agent: Replication and RDA IIS Server Agent: Replication and Remote Data Access OLEDB QP/Cursor Engine/ES OLEDB HTTP Storage Engine / Repl Tracking Occasionally Connected CLIENT SERVER
Remote Data Access (RDA) Very simple read/write access to data in remote SQL Server 7 or later Cached remote data Rows are pulled down to the client Rows can be tracked and later pushed back to server, or Non-tracked, local only Connection flexibility Continuous connection Intermittent connections Submit SQL to server Pull down a set of rows, update and push back up again Can copy an entire table down to work with Tracked changes means that RDA keeps a track of what has changed, so that later on just changes can be sent back to the server when synchronising. Local only means you would lose this information
Remote Data Access (RDA) Applications can use RDA via three methods: Pull: Client submits SQL query, creating a new table of qualifying rows. Changes made to table can be tracked or non-tracked Push: With tracked changes, Push method sends modified rows back to server and applies them SubmitSQL: Client submits any valid SQL Server SQL statement which is forwarded to SQL Server for execution
RDA Code // Initialize the RDA object. SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess(); rda.InternetUrl = "http://marcpe02/sqlce/sscesa20.dll"; rda.LocalConnectionString = @"Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=\pubsce.sdf"; rda.Pull( "Sales", "Select * from Sales", rdaOleDbConnectString, RdaTrackOption.TrackingOnWithIndexes, "ErrorTable");
Merge Replication Based on SQL Server 2000 bi-directional implementation Ideal for mobile use Update data on client and/or server Merge and resolve conflict based on server-side rules Easy synchronization when connected Flexible data partitioning: vertical, horizontal, and dynamic Anonymous pull subscriptions Auto Ranged Identity Support Vertical = Select Columns Horizontal = Select Rows Dynamic = Based on filter criteria, such as the current connected user using SUSER_SNAME()
Replication code SqlCeReplication rep = new SqlCeReplication();; // Set the Replication object. rep.InternetUrl = "http://marcpe02/sqlce/sscesa20.dll"; rep.InternetLogin = ""; rep.InternetPassword = ""; rep.Publisher = “marcpe02"; rep.PublisherDatabase = "northwind"; rep.PublisherLogin = "pubs"; rep.PublisherPassword = "pubs"; rep.Publication = "northwindpublisher"; rep.SubscriberConnectionString = LocalDB; rep.Subscriber = "HP2210"; // Add a new subscripton and create the local database file rep.AddSubscription(AddOption.CreateDatabase); // Transfer the initial snapshot of data if this is the first // time is this called. Subsequent calls will transfer only the // changes to the data rep.Synchronize();
DataSet vs SQL CE DataSet SQL CE Inbuilt to Compact Framework Need to deploy Extra runtime RAM requirement Limited filter capability Rich ANSI SQL support Serializable to XML Persists on filesystem Supports Web services Remote data access and synchronization over HTTP Works with .NET Runtime Requires SQL Server Performance limited to smaller data Large databases up to 2GB No inbuilt security 128-bit Encryption support Client Access Licensing
Microsoft Message Queue
MSMQ Implements asynchronous communications Provides guaranteed delivery, efficient routing, priority based messaging. Usernames storage support roaming NIC tracking Transparent, salvageable storage Small footprint ~150KB Support for private queues only NIC Tracking – Tracks whether the network is up or down Messages can be stored locally and then forwarded – could put on an SD card
Communication Options Transport Summary Web Services Internet Ready Industry standards / High level of interoperability Highly extensible Application synchronization SQL CE Designed for data manipulation Synchronization Enabled Can communicate to SQL Server Secure (Smartphone support coming) MSMQ Guaranteed delivery Extension of backend MSMQ systems Network tracking built in (Managed support coming)
Other Considerations Performance Security & Deployment Raw Application Perceived Response Backend Servers Security & Deployment See Securing and Deploying your Mobile Application Security session is on the CD
Performance - WinForms Load and cache Forms in the background Populate data separate from Form.Show() Pre-populate data, or Load data async to Form.Show() Parent controls top-down e.g. Form panels controls Keep event handling code tight Process bigger operations asynchronously Blocking in event handlers will affect UI responsiveness Rather than doing o.Controls.Add ( child ) , call child.Parent = parent
Performance - XML Use XmlTextReader and XmlTextWriter Smaller memory footprint than using XmlDocument XmlTextReader is a pull model parser which only reads a “window” of the data Design XML schema first, then code Understand the structure of your XML document Use elements to group Allows use of Skip() in XmlTextReader Use attributes to reduce size
Performance - Data If data is local…instead of DataSet… Leverage SQL CE native in-proc database Query data using DataReader Use TableDirect command type for fast index searches Equivalent to “SELECT * FROM foo” Limit open SqlCeCommand/DataReaders Dispose when complete If data is remote… Use SQL CE replication When using Web Services Save data locally in SQL CE for faster access and storage Don’t save remote DataSets as XML to device If you do, save Schema as well
Performance - Server Aggregate multiple Web service calls where possible Stress test the server, find your limits Implement stateless calls for web farms For large user base, partition times users can replicate SQL data Replication from CE can kill the server so you may want to partition times where users can sync up
Deployment Considerations Installation CAB format for installation Desktop ActiveSync Web page URL Email Service Indication / Service Loading Messages SD/CF Card What is user base? Ongoing How to ensure users are running latest versions? Operators can send out Service Indication / Service Loading messages, to for instance tell you that you need to update code App Updater Block?. Could SMS a user to say that there is a new version available.
Summary Store and Forward connectivity can help connected/disconnected environment Web Services Standardised Extensible SQL CE Designed for data manipulation Secure MSMQ Extension of backend MSMQ systems Guaranteed delivery Design with performance in mind
Resources Patterns & Practices .NET Compact Framework FAQ http://www.microsoft.com/resources/practices/ .NET Compact Framework FAQ http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx SharpZipLib Compression Library (note licensing) http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx IIS 6.0 HTTP Compression http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/windowsserver2003/maintain/operate/iis6perf.asp SQL CE and SQL 2000 sp3a http://www.microsoft.com/sql/ce/downloads/sp3.asp MSMQ http://msdn.microsoft.com/msdnmag/issues/01/12/MSMQCE/default.aspx
© 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.