为什么需要 Web 服务来从 Silverlight 访问数据库?
我目前正在研究几个选项来创建一个新的应用程序,该应用程序可以由封闭的 Intranet 中的多个用户使用浏览器访问。
我考虑使用 Silverlight,因为它的用户友好性及其 WPF 设计非常接近未来用户习惯的富客户端。
该项目(当然)还需要访问内联网内的数据库,因此我浏览互联网以了解如何处理数据访问。我很惊讶地发现您显然必须使用 Web 服务与数据交互,如 this SO post 指向 本教程(使用网络服务的多种方法之一)。
我已经在 Intranet 中创建了各种与数据库交互的富客户端,但我很惊讶被迫使用 Web 服务。
事实上,我确实了解网络服务的优势;它提供的安全性以及通常在软件架构中创建良好 DAL 的所有其他功能。但是,我不明白为什么您不能简单地创建(例如)一个包含 Linq to SQL 类的库,并在 silverlight 项目中使用该库作为引用来直接访问数据,就像使用经典的富客户端应用程序一样。据我所知,通过这样做,您可以将访问数据存储在应用程序的连接字符串中,但我不明白为什么它不能与 silverlight 客户端一起使用。
更新:
那么,有两个问题:
- 我们实际上必须通过网络服务访问数据吗?
- 如果是这样,为什么它与经典的富客户端方法不同?
- Silverlight 5 能让我做这样的事情吗?
I am at the moment looking into several options to create a new app which can be accessed using the browser by multiple user in a closed intranet.
I thought about using Silverlight for its user-friendliness and its WPF design so close to the rich clients the future users are used to.
The project (of course) requires access to a database also within the intranet, hence I browsed the internet to see how data access was handled. I was surprised to see that you apparently have to use web services to interact with data, as mentioned in this SO post which points this tutorial (one of many ways to use webservices).
Having already created various rich client within an intranet all interacting with database, I was surprised to be forced to use web services.
Indeed, I do understand the advantages of the web services; the security it provides, and all the other features of created a good DAL generally in software architecture. However, I can't see why you can't simply create (for example) a library containing the Linq to SQL classes and use this library as reference in the silverlight project to access data directly as you can do with classic rich client application. I understand that by doing that, you store the access data within the connection string of the app, but I can't see why it shouldn't work with a silverlight client.
UPDATE:
So, two questions:
- Do we actually have to access data through web services?
- If so, why is it different from the classic rich client approach?
- Will Silverlight 5 enable me to do such thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与 WPF 不同,Silverlight 不使用或无法访问完整的 .NET Framework。它在自己的、受限的 CLR 和框架下运行。
在决定包含什么和省略什么时,我们决定将所有数据访问组件排除在 Silverlight 之外。这确实使得上面所说的直接创建“使用SQL的库”变得不可能了。
通过使用 WebServices(或 WCF,这实际上是首选方法),您只需要能够创建和访问服务引用,这在 Silverlight 中受支持。
Silverlight, unlike WPF, doesn't use or have access to the full .NET Framework. It's running under it's own, restricted CLR and framework.
In the decision of what to include and what to omit, it was decided that all of the data access components were left out of Silverlight. This really makes it impossible to directly create the "library using SQL" as mentioned above.
By using WebServices (or WCF, which is really the preferred method), you are only required to be able to create and access the service references, which is supported in Silverlight.
Silverlight 在客户端工作站上运行,而数据库驻留在某个服务器上。托管数据库的一方会遇到各种各样的安全问题,必须使其能够被客户端软件直接访问。使用 Web 服务等机制可以将数据库隐藏起来,远离客户端软件。
同样,使用 Web 服务作为数据访问方法意味着 silverlight 不需要知道数据库如何工作,因此您的数据可以位于 sql server、oracle、mysql 甚至平面文件中,这对 silverlight 客户端没有区别。这确实是一个聪明的方法。
Silverlight runs on the client workstation while the database resides on a server somewhere. There would be all sorts of security issues of the party hosting the database had to make it accessable to client software directly. Using a mechanism like web services hides the database away from client software.
As well, using web services as a data access method means that silverlight doesn't need to know how databases work so your data can be in a sql server, oracle, mysql or even flat files, and it makes no difference to the silverlight client. It really is a smart way to do it.