views:

116

answers:

3

This question is related to this other question I recently asked...

http://stackoverflow.com/questions/417789/cf-net-exception-and-other-logging

I am generating log messages to be sent to a server using a webservice over a GPRS connection and I want to simply queue these messages in the case the connection to the server is not available. Later I may also want to batch them to save bandwidth. What is best (easiest) way of doing this using cf.net. I need the queue to be somehow persisted across app restarts and preferably across device restarts.

Does anyone have any advice? Or better still a code example :)

Many Thanks.

+1  A: 

I've used a SQL Compact database for doing this sort of thing (and a lot more). I've never had any problems and you probably already know all the skills required. Basically store the messages in the database and delete them once they are successfully uploaded.

Using MSMQ for the Compact Framework is a decent alternative if you are familiar with regular MSMQ.

As an aside, we conserve the power on Windows Mobile devices by switching the phone capabilities off all the time other than when it is need, ie. for GPRS data transfer. This can improve battery life considerably if it is viable for your situation (ours are never used apart from our application, they are scanners with WM on them rather than mobile phones).

Garry Shutler
+2  A: 

Typically what I've done is push the data into a database table (SQLCE is my typical route). When I need to push something to the web service, I send it to the dispatcher, which in turns puts it into the database. The dispatcher has a background thread that pulls data out of the database, sends it, then does a database delete upon successful send. It also monitors connection state.

A queue in the dispatcher is a little cleaner and faster, but your desire to persist across app and device restarts requires persistent storage, so a database is probably the simplest mechanism.

ctacke
Are you the same ctacke who works for OpenNetCF with who I corresponded yesterday on the SDF forum about wrapping GetDevicePowerState in SDF? If so, Hi!
Christopher Edwards
One and the same.
ctacke
A: 

Have a look at using message queues on the client to store the logs, with a service to poll and attempt to send to the server at regualar intervals, batching where possible. Successful sends can remove the log from the queue.

Here's a good starting point: MSDN