views:

1743

answers:

15

Okay, I will shortly be starting down the path of windows mobile development. I know nothing about the subject really and I am looking for people with experience to let me know of any gottchas you may know of.

Right now I dont even have a breif of what is requied but the assumption is that the application will be very little more than a bunch of CRUD forms for updating data. The only other requirment knowladge I have is that the application will need to support offline storage when there is no signal avaliable. This in turn will obviously require some kind of syncronization when signal returns.

My initial thoughts are that the application will primarily be a front end to interact with a web service layer. Im assuming that WCF will be an appropriate technology for building these services? I also thought that SQL Server CE would be a good route to go down with regards to the offline storage issues.

Any knowlage that you feel is useful within this domain would be appreciated. Advice, links, books anything appreciated.

EDIT: It has been noted that there are two ways to go with off-line synchronization. To either use some form of message queuing or to use SQL synchronization tools. Could anyone offer a good comparison and introduction to these?

EDIT 2: After a little more digging I get the impression that there are basically 3 different approaches I can use here:

  1. Emmbeded Database to query against then syncronization online, when able
  2. MSMQ along with .NET remoting
  3. WCF with ExchangeWebServiceMailTransport bindings using Exchange Server.

Now, there has been a nice few points raised on the first issue, and I think I understand at some level the issues I would face. But I'd like to get a little more information regarding MSMQ implementations and using WCFs new bindings.

+2  A: 

you might want to refer to this:

getting-started-with-windows-mobile-development

melaos
+1  A: 

You shouldn't be intimidated for windows mobile development. It isn't much different from desktop development. I strongly recommend that you use .NET Compact Framework for development and not C++/MFC.

Some useful links:

  • Mobile section at the Code Project. You would find a lot of articles, a little digging is needed to find the appropriate one.
  • Smart Device Framework from OpenNetCF offer valuable extensions to the compact framework.
  • When you install the Mobile SDK, you will find under the Community folder links for the Windows Mobile and CF framework blogs. These are also valuable resources.

Regarding your application, you are right about the WCF and the SQL Server CE. These are the proper ways for handling communication and storage.

Some hints for people coming from a desktop world:

  • You need to have some sort of power management. The device may automatically go to suspend state. Also, you shouldn't consume power when you don't have to.
  • Network connectivity is a difficult issue. You can register notifications for when a specific network (Wi-Fi, GPRS) becomes available or unavailable. You can also set the preferred means of communication.
  • Make the UI as simple as possible. The user uses his thumb and/or a pen and he is probably on the move.
  • Test in a real device as early as possible.
kgiannakakis
A: 

I had to do this once. Weird setup with Macs for development, and we were all Java programmers. And a short deadline. PowerPC macs too, so no chance to install Windows for Visual Studio development, never mind that the money for this would never have appeared.

We ended up writing applications using Java, running on the IBM J9 virtual machine, with SWT for a user interface. Entirely free development stack. Easy to deploy. Code ran on any platform we desired, not just PocketPC/WinMob.

Most of the work was on the server side anyway - the database, the web service server. The logic. The reporting engine. The client side wasn't totally simple however - would get the form templates from the server (because they changed frequently), the site details (multi-site deployment), generate a UI from the form template (using some SWT GUI components that are wonderful for PocketPC development, like the ExpandBar), gather data with a point and click interface (minimising keyboard entry where possible), and then submit it back to the server.

For offline storage we used XML files on the device itself. More than enough for our needs, but yours may differ. Maybe consider SQLite?

JeeBee
+12  A: 

Here a few words from my experience so far (about 9 months) of .net Windows Mobile development.

  1. Well you are occasionally connected. (Or more likely occasionally disconnected). You have to choose whether you are going to use messaging with queues (i.e. WCF/SOAP/XML or something like it) or database synchronisation. I choose the SQL synchronisation route so I can't really comment on messaging. The SQL synchronisation route is not hassle free!

  2. If you go down the sync route with SQL compact like me you basically have two choices. SQL Server merge replication or the newer ADO.NET Synchronisation services. If you choose the former you need to be really careful with your DB design to ensure it can be easily partitioned between mobile subscribers and the publisher. You really need to think about conflicts, and splitting tables that wouldn't normally be split in a normalised DB design is one way of doing that. You have to consider situations where a device goes offline for some time and the publisher DB (i.e. main DB) and/or a subscriber alters the same data. What happens when the device comes back online? It might mean resolving conflicts even if you have partitioned things well. This is where I got burnt. But SQL Merge Replication can work well and reduces the amount of code you have to write.

  3. Roll your own DAL. Don't attempt to use datareaders etc. directly from UI code and don't use typed datasets either. There may be third party DALs that work with Windows Mobile (i.e. I know LLBLGEN does, might be worth a look) but Linq-to-SQL is not supported and anyway you need something lightweight. The chances are the DAL won't be too big so roll it yourself.

  4. If you are using .net you'll probably end up wanting some unimplemented platform features. I recommend using this inexpensive framework to give you what your missing (especially as related to connectivity and power management) - http://www.opennetcf.com/Products/SmartDeviceFramework/tabid/65/Default.aspx

  5. Windows Mobile devices partially switch off to save power when not in use. If you are doing a polling type design you'll need to wake them up every x mins. A normal .net timer class won't do this. You'll need to use a platform feature which can be used from OpenNetCF (above). The timer class is called LargeIntervalTimer and is in the OpenNetCF.WindowsCE assembly/namespace (I think).

Good Luck!

Christopher Edwards
Thanks Chris, so regarding rolling your own DAL - I take it NHibenate is not advised, as this was going to be my initial route.
Owen
Hi Owen. The honest answer is I'm not sure about NHibernate on Windows Mobile. I'd try to do some tests (or find someone else who has, SO?) before going down that route. SQLCE has lightweight DA objects like the SqlCeResultSet, and I doubt that NHibernate will use them.
Christopher Edwards
NHibernate does support SQL CE, that wasn't my concern it was just that you mentioned that the DAL should be lightweight and I don't know how lightweight you mean. Don't think NHibernate is really heavy but it is a framework after all.
Owen
There is an SqlServerCeDriver for NHibernate, I didn't know that. I'd try it out, or at least look at the source code. Typed SQLDatasets are too heavy weight, really slow. If the SqlServerCeDriver is using SQLCE DA objects under the covers it might work well.
Christopher Edwards
Thanks Chris, very helpful. I just need a comparison to the message queing approach now. Cheers, for that.
Owen
I'm not sure NHibernate would be a good idea as it's reflection heavy although I haven't tried it myself.
Quibblesome
Quarrelsome - as with ny edit I have just found out that standard assemblies could not be added to window mobile applications anyway so I guess NHibernate is completely out of the question. What are this issues with reflection though?
Owen
+6  A: 

SqlCE is only one of the options available for local data storage on a Windows Mobile device, and although it's an excellent database it has limitations. For one thing, SqlCE will not work (period) under encryption (in other words, if your user encrypts the location where your SDF file is, you will no longer be able to access the data).

The second (and most critical) weakness of SqlCE lies in the RDA/Merge Replication tools. SqlCE Merge Replication is not 100% reliable in situations where the network connection can drop during replication (obviously very common in Windows Mobile devices). If you enjoy trying to explain missing or corrupted data to your clients, go ahead and use SqlCE and merge replication.

Oracle Lite is a good alternative to SqlCE, although it too doesn't work properly under encryption. If encryption is a potential problem, you need to find a database engine that works under encryption (I don't know of one) or else write your own persistence component using XML or something.

Writing a WM application as a front end that primarily interacts with a web service in real time will only work in an always-connected environment. A better approach is to write your application as a front end that primarily interacts with local data (SqlCE, Oracle Lite, XML or whatever), and then create a separate Synchronization component that handles pushing and pulling data.

Again, SqlCE merge replication does this pushing and pulling beautifully and elegantly - it just doesn't work all the time. If you want a replication mechanism that works reliably, you'll have to write your own. Oracle Lite has something called a snapshot table that works very well for this purpose. A snapshot table in Olite tracks changes (like adds, updates and deletes) and allows you to query the changes separately and update the central database (through a web service) to match.

MusiGenesis
"a web service in real time will only work in an always-connected environment" - I get this but isn't this why things like MSMQ exists? Isn't using an embedded database and synchronizing that way just 1 option?
Owen
P.S. I am actually asking here, I really don't know. The two solutions could be intermingled somehow for as much as I know.
Owen
MSMQ might be relevant to this problem in an environment where the PDA is connected most of the time (say 99%) but experiences occasional outages. In such a situation, you wouldn't necessarily need a database at all. In the WM applications that I've written, network availability is more like ...
MusiGenesis
... 5-10%, so having a local database is critical. Important quote about MSMQ from MSDN: "Message Queuing is not a database and does not provide database functionality".
MusiGenesis
Thank you MusiGenesis, you have been very helpful +1
Owen
No problem. I wish there were more WM questions on SO. :)
MusiGenesis
Erm... SQLCE databases can be encrypted and work on Windows Mobile. And have been able to for some time. Although in 3.5 SP1 it's stronger. See here - http://download.microsoft.com/download/f/7/2/f72ebbf8-4df1-4800-b4db-c2405c10d937/ReadmeSSC35-ENU.htm
Christopher Edwards
Or maybe you mean they won't work on file encrypted SD cards or something??
Christopher Edwards
@ChrisE: I meant the latter, that they won't work on file encrypted SD cards. This can be a surprise, if your client suddenly mandates file encryption.
MusiGenesis
+4  A: 

This thread I just posted on SO a few days ago has proven to be a great resource for me thus far.

Also the Windows Mobile MSDN WebCasts are a wealth of information on everything from just getting started up to advanced development.

Mat Nadrofsky
Wow, very helpful. Cheers.
Owen
+3  A: 

I would suggest Sqlite for local storage. From the last benchmark I ran it was much better than SqlCe and you don't have to do stupid things like retain an open connection for performance improvements.

Trade-offs being that the toolset is less rich and the integration with other MSSql products is nil. :(

Quibblesome
Upvote - been there done that too.
le dorfier
A: 

There are a couple links you can check out to start with:

  1. http://developer.windowsmobile.com
  2. http://msdn.microsoft.com/en-us/windowsmobile/default.aspx

If you have a sticking point while developing, there are also Windows Mobile dedicated chats on MSDN that you can attend and ask your questions. The calendar hasn't been updated yet, but the next ones should be in January. You can find the schedule here: http://msdn.microsoft.com/en-us/chats/default.aspx

A: 

If you can, try to start from the user use cases and work back to the code, rather than vice versa. It's really easy to spend a lot more time working on the tools than working on the business problem. And thinking through user requirements will help you consider alternate strategies, because a lot of the patterns you know from normal .NET don't apply.

I've done lots of intermittent application development of exactly the type you are describing, and an on-board database works just fine. The MSMQ/WCF stuff just adds conceptual overhead without adding much value. You need a logical datastore locally anyway, and replication at this level is a simple concept that you want to keep simple, so the audit trail is easily monitored and debugged. MSMQ and WCF tend to hide things in unfamiliar places.

I upvoted the SqlLite suggestion BTW. MS doesn't have their persistence story stabilized yet for CE.

le dorfier
Does sql lite support SPROCS and views as it seems that CE doesn't. Also what are the synchronization options are available with sql lite companison to SQL Server CE.
Owen
I don't know your requirements, but for my purposes I wouldn't want generic blind synchronization anyway, but rather asynch refreshable validation tables in and asynch transaction queue-table out, with retries on a timer.
le dorfier
Yes it supports (read-only) views. No stored procs, but I'd implement a DAL class to do that sort of thing anyway. Full info here - http://www.sqlite.org/docs.html
le dorfier
A: 

I am going to add an additional question to this post, as its been active enough and hopefully will be helpful to others as well as me. Ok, so after playing around I now realize that standard class libraries cannot be included in windows mobile applications.

Now the overwhelming advice here seems to be use an embedded database, though I now do have use cases and it appears that I will need to have document synchronization as well as relational data. With this in mind service layer interaction seems inevitable. So my question is how would I share common domain objects and interfaces between the layers?

Owen
A: 

"Document synchronization" - does that mean bidirectional? Or cumulative write-only? I can think of mobile architectures that would mainly collect and submit transactions for a shared document - if that's your requirement, then we should discuss offline - it's a long (and interesting) conversation.

le dorfier
My requirements would include a level of bi-directional communication.
Owen
A: 

Owen you can share code from Compact Framework -> Desktop, it's only Desktop -> Compact Framework that has compatability issues if you use certain objects that are not supported by the CF.

While a desktop lib doesn't work on CF a CF lib WILL work on the desktop, you can also run CF.exes on the desktop!

Just create a CF library as the project that defines your base objects / interfaces etc.

Quibblesome
Thanks for that quarrelsome. Makes sense that this would be the case.
Owen
+1  A: 

"24 Hours of Windows Mobile Application Development" from the Windows Mobile Team Blog has some good resources

Peter Mourfield
A: 

This book sshould e essential reading for all Windows Mobile developers: http://www.microsoft.com/learning/en/us/books/10294.aspx

Matt Lacey
+1  A: 

For the database replication bit I highly recommend Sybase Ultralite. In terms of flexibility and performance it knocks the socks off SQL CE

Conrad