views:

180

answers:

7
+1  Q: 

N-Tier with C# ?

I am looking at writing a WinForms app and getting stumped over what seems to be simple issue.

There is a server and database (SQL Server) Open ports are HTTP, HTTPS

There is a WinForms client. It needs to connect a TCP/IP stream (possibly HTTP, SOAP, REST) to the server.

Sometimes the WinForms client goes off-line and then the WinForms client stores its data in a database.

When the WinForms client goes on-line to server, it synchronizes data to the server, gets all the latest data from the server and updates local database.

How do I do that?

Newbie question

+2  A: 

No idea how actively this is still being supported by Microsoft, but you might check out the Smart Client Software Factory, it seems to support offline mode and smart reconnecting like you need.

http://msdn.microsoft.com/en-us/library/ff709809.aspx

Sam
A: 

Generally, you need a local database, or at least a local cache.

Steven Sudit
hi,there is already database on local WinForms client. Just not sure how to sync to server.
buttercup
As nonnb said, that part isn't so simple. The easiest way is to keep the flow uni-directional, always wiping out the local database by replacing it with an extract from the real one. Otherwise, you could use timestamps to help you determine which records have changed on the client side since the last sync. However, you'd also have to make sure not to overwrite anyone else's changes.
Steven Sudit
+1  A: 

You could approach this with a 'Service' mindset - Write a WebService (preferably a WCF service) - that forms the synchronization tier between your Winforms app. and remote database.

So, you would have your
1. Local WinformsApp. with a local database (as functional/lightweight as you want it to be)
2. WebService
3. Remote app./DB

Shankar Ramachandran
+1  A: 

IMHO this isn't usually as simple as it may sound

  • If you were able to go DB to DB, then SQL replication could be the simplest mechanism for synchronisation.
  • However, since it sounds like you are using a SOA approach, you might need to look at frameworks which have offline support built in, such as the Ent Lib Composite Application Block and Smart Client Software Factory
  • You might also look at using Queues (e.g. MSMQ) to accomodate network connectivity problems.
nonnb
+2  A: 

As you've conceded, this question shows you might not know where to begin looking for how to architect this kind of application.

I'd start here: http://msdn.microsoft.com/en-us/library/ms973279.aspx

The offline architecture you've described is a little tougher for a newbie than not supporting this, consider making the application only work online first, then add offline functionality.

Also, if you have a web server you will almost always use HTTP, SOAP and REST are strategies that sit on top of HTTP. I cannot recommend that a new developer look at any server communication using direct TCP/IP.

Edit: Answer to related question - there are tons of ORMs and service builders, not a lot of them have built in support for offline workflow but ODX does, but it might be a bit out of date. NHibernate and any of the projects in the Castle Project are very popular components for what you're looking to do also.

marr75
+1  A: 

Microsoft Sync Framework (http://code.msdn.microsoft.com/sync) + WCF solution here: http://code.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=3762

Database synchronisation is not an easy task to get started with, by any means. Good luck.

Keith Blows