N 层与 C#?
我正在考虑编写一个 WinForms 应用程序,并被一个看似简单的问题所困扰。
有一个服务器和数据库(SQL Server)开放端口是HTTP,HTTPS
有一个WinForms客户端。它需要将 TCP/IP 流(可能是 HTTP、SOAP、REST)连接到服务器。
有时,WinForms 客户端会离线,然后 WinForms 客户端会将其数据存储在数据库中。
当WinForms客户端与服务器联机时,将数据同步到服务器,从服务器获取所有最新数据并更新本地数据库。
我该怎么做?
新手问题
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
正如您所承认的,这个问题表明您可能不知道从哪里开始寻找如何构建此类应用程序。
我从这里开始: http://msdn.microsoft.com/en- us/library/ms973279.aspx
对于新手来说,您描述的离线架构比不支持此架构要困难一些,请考虑首先使应用程序仅在线工作,然后添加离线功能。
另外,如果您有 Web 服务器,您几乎总是会使用 HTTP,SOAP 和 REST 是基于 HTTP 的策略。我不建议新开发人员查看使用直接 TCP/IP 的任何服务器通信。
编辑:回答相关问题 - 有大量的 ORM 和服务构建器,其中没有很多内置了对离线工作流程的支持,但 ODX 确实如此,但它可能有点过时了。 NHibernate 和 Castle 项目中的任何项目都是非常受欢迎的组件,适合您想要做的事情。
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.
不知道微软对此的支持有多积极,但您可以查看智能客户端软件工厂,它似乎支持您需要的离线模式和智能重新连接。
http://msdn.microsoft.com/en-us/library/ff709809。 ASPX
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
您可以用“服务”思维来解决这个问题 - 编写一个 WebService(最好是 WCF 服务) - 它形成 Winforms 应用程序之间的同步层。和远程数据库。
所以,你会有你的
1.本地WinformsApp。使用本地数据库(如您所希望的功能/轻量级)
2.Web服务
3.远程应用程序/DB
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
以下是一些教程/资源的链接:
http://www.codeproject.com/KB /architecture/third_tier_architecture.aspx
http://services.community.microsoft.com/feeds/feed/query/tag/n-tier/eq/tag/visual%20basic/ eq/and/locale/en-us/eq/and
http ://msdn.microsoft.com/en-us/library/bb384570.aspx
http://msdn.microsoft.com/en-us/library/bb384398.aspx
Here are some links to tutorials/resources:
http://www.codeproject.com/KB/architecture/three_tier_architecture.aspx
http://services.community.microsoft.com/feeds/feed/query/tag/n-tier/eq/tag/visual%20basic/eq/and/locale/en-us/eq/and
http://msdn.microsoft.com/en-us/library/bb384570.aspx
http://msdn.microsoft.com/en-us/library/bb384398.aspx
恕我直言,这通常不像听起来那么简单
IMHO this isn't usually as simple as it may sound
Microsoft 同步框架 (http://code.msdn.microsoft.com/sync) + WCF解决方案在这里:
http://code.msdn.microsoft.com/sync/ Release/ProjectReleases.aspx?ReleaseId=3762
无论如何,数据库同步并不是一项容易上手的任务。祝你好运。
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.
通常,您需要一个本地数据库,或者至少需要一个本地缓存。
Generally, you need a local database, or at least a local cache.