简体   繁体   English

希望创建一个客户端应用程序(WPF)来对远程数据执行CRUD操作

[英]Looking to create a Client-Side Application (WPF) to perform CRUD operations on remote data

I'm being handed a project to develop an application I'm thoroughly excited about. 我正在接受一个项目来开发一个我非常兴奋的应用程序。 The problem is that I'm not entirely sure how to implement one specific requirement. 问题是我不完全确定如何实现一个特定的要求。

The application needs to be a client-side application (so I'm using WPF to develop it) and needs to perform CRUD operations to a remote server (so others can also access this data). 应用程序需要是客户端应用程序(因此我使用WPF来开发它)并且需要对远程服务器执行CRUD操作(因此其他人也可以访问此数据)。 The main hitch I'm stuck on is that this client application will not only be run from a specific network, but one of the core users will be using it from home as well. 我坚持的主要障碍是这个客户端应用程序不仅将从特定网络运行,而且其中一个核心用户也将在家中使用它。 I'm not sure how to expose the data to the internet securely. 我不确定如何安全地将数据暴露给互联网。

I was originally developing the app using just LINQ 2 SQL, and imagining that I would simply forward ports to a dedicated machine running SQL Server, but that's probably a horrendous idea. 我最初使用LINQ 2 SQL开发应用程序,想象我只是将端口转发到运行SQL Server的专用机器,但这可能是一个可怕的想法。 Doing some research, it looks like I'm supposed to use WCF to create a service then run that on a machine - and have the WPF client applications use that instead. 做一些研究,看起来我应该使用WCF创建一个服务,然后在一台机器上运行它 - 并让WPF客户端应用程序使用它。

That feels like a bit of extra work here, especially since I'm using this project to learn WPF. 这感觉就像在这里做了一些额外的工作,特别是因为我正在使用这个项目来学习 WPF。 I've not even looked into WCF yet. 我还没有考虑过 WCF。 Do I have another alternative? 我有另一种选择吗? Is my original concept of just exposing the SQL Server to the internet really all that bad ? 我最初将SQL Server暴露给互联网的原始概念真的那么糟糕吗?

Thanks! 谢谢!

First, I agree that you should avoid exposing your database to the internet... it's like leaving a baby alone in the woods overnight (there are creatures on the prowl for sport and profit). 首先,我同意你应该避免将你的数据库暴露在互联网上......这就像是让一个孩子一夜之间独自留在树林里(有拯救生物和利润的生物)。

You do have a few options though. 你确实有几个选择。 For one, if the company has a network admin, you might consider getting a VPN set up. 首先,如果公司有网络管理员,您可以考虑设置VPN。 That way employees could connect directly to the SQL Server from home, inside the firewall. 这样,员工可以在家中,防火墙内直接连接到SQL Server。

Failing that, I think WCF with Linq-to-SQL isn't a bad option. 如果做不到这一点,我认为使用Linq-to-SQL的WCF并不是一个糟糕的选择。 I built an application with those two, and they work pretty well together-- I had the Linq-to-SQL table entities themselves as the WCF data contract. 我用这两个构建了一个应用程序,它们可以很好地协同工作 - 我将Linq-to-SQL表实体本身作为WCF数据协定。 One thing I would recommend is to choose a simple design pattern for your CRUD operations, and stick to it as much as possible-- the repository pattern with Load, Find, InsertOrUpdate, and Save. 我建议的一件事是为您的CRUD操作选择一个简单的设计模式,并尽可能地坚持它 - 使用Load,Find,InsertOrUpdate和Save的存储库模式。

Is my original concept of just exposing the SQL Server to the internet really all that bad? 我最初将SQL Server暴露给互联网的原始概念真的那么糟糕吗?

Yes. 是。 There are many caveats and you simply shouldn't (I wanted to link every word in that sentence to another source, but you catch my drift). 许多 警告 ,你根本不应该 (我想把那个句子中的每个单词都链接到另一个来源,但你抓住了我的漂移)。

WCF is definitely the way to go here, since it has lots of options to secure it and is easily consumed from within WPF . WCF绝对是这里的方式,因为它有很多选项保护它并且很容易从WPF内部消费

While exposing the database and accessing it directly seems like the easiest solution, that's hardly ever the best one. 虽然公开数据库并直接访问它似乎是最简单的解决方案,但这几乎不是最好的解决方案。 You will have to learn a few new techniques, but you'll benefit from it on the long run. 您将不得不学习一些新技术,但从长远来看,您将从中受益。

There are a lot of different angles on this question, but if I am understanding what you are asking... 这个问题有很多不同的角度,但如果我理解你的要求......

To resolve your remote user issue: SQL Server can be securely configured to be exposed to the internet for a software as a service application to connect to. 解决远程用户问题:可以将SQL Server安全地配置为暴露给Internet,以便将软件作为要连接的服务应用程序。 Or you could have the remote user VPN into the network that the SQL server resides on. 或者您可以让远程用户VPN进入SQL服务器所在的网络。

For a development approach I would suggest MVVM. 对于开发方法,我建议使用MVVM。 It works great with WPF and will allow you to learn WPF first with your own custom data layer. 它适用于WPF,可以让您首先使用自己的自定义数据层学习WPF。 Then when you're comfortable you can refactor to use WCF and deliver a quality app. 然后,当您感到舒服时,您可以重构使用WCF并提供高质量的应用程序。

why not use WCF Data Services - http://msdn.microsoft.com/en-us/library/cc668772(v=vs.103).aspx . 为什么不使用WCF数据服务 - http://msdn.microsoft.com/en-us/library/cc668772(v=vs.103).aspx If you need it to be secure then see this http://msdn.microsoft.com/en-us/library/dd728284.aspx 如果您需要它是安全的,请参阅此http://msdn.microsoft.com/en-us/library/dd728284.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM