WCF RIA 服务中的业务逻辑位置
我刚刚学习如何使用 WCF RIA 服务编写应用程序。关于该主题的大多数教程都会从数据库中获取数据并将其显示在客户端中。我不清楚应该将业务逻辑放在哪里。我本质上需要从客户端获取输入,对数据库执行一些查询,然后对其执行一些计算并在客户端上显示计算结果。我是否从数据库检索数据到客户端并在客户端执行操作,是否在服务器的域类中执行操作并返回结果或其他内容?
任何帮助表示赞赏
I'm just learning how to write applications using the WCF RIA Services. Most tutorials on the topic go upto fetching data from a database and displaying it in the client. I am not clear on where I should be placing my business logic. I essentially need to take input from the client, perform a few queries to the database, then perform some computations on it and display the result of the computations on the client. Do I retrieve data from the database to the client and perform the operations there, do I perform the operations at the server's domain class and return the result or something else?
Any help is appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在服务器或客户端上执行此操作,但在客户端上执行此操作允许您使用客户端计算机/处理器来执行计算。如果有大量用户,将工作推送到客户端可能会对服务器性能产生很大影响。
You can do it on the server or client but doing it on the client allows you to use the client machine/processor to perform the computations. If there are a large number of users, pushing work onto the client can make a big difference in server performance.
性能是考虑因素之一,但您还必须考虑您的 IP。请记住,Silverlight 应用程序已交付给客户端,并且客户端上的所有 .Net 代码都可以重新设计。是的,您可以隐藏(sp!)代码,但这是部署中的额外步骤。无论如何,如果您的 IP 很有价值,我建议在客户端上完成数据收集和验证(无论如何,这只是一个很好的做法)。工作返回到服务器后,您可以注入/拦截 WCF RIA 服务请求并执行“附加”工作。我在这里问了一个类似的问题:ChangeSet Complete
Performance is one consideration, but you must also consider your IP. Remember a Silverlight application is delivered to the client, and all the .Net code on the client can be re-engineered. Yes you can obviscate (sp!) the code, but that is a an extra step in the deployment. Regardless, if you IP is valuable, I would recommend that the data collection and valiation be done on the client (this is simply good practise anyway). After the work is back to the server, you can inject/intercept the the WCF RIA Services request and peform "additional" work. I asked a simliar question here: ChangeSet Complete
WCF RIA 服务背后的想法是您的业务逻辑可以在客户端和服务器之间共享。显然,您无法构建复杂的计算,但是围绕业务类的所有验证和规则都应该位于 对象元数据,以便它自动显示在客户端和服务器上。
进行这些类型的计算时要记住的最重要的事情是:
1) 您发送给客户端的任何代码都可以被客户端查看。
2) 在客户端上完成的任何计算都可能被客户端更改。
因此,如果您有订单服务并且仅在客户端上计算订单总额,则恶意用户可能会向您发送总额计算错误的订单。
The idea behind WCF RIA Services was that your business logic can be shared across both the client and the server. Obviously you can't build in complex calculations, but all of your validation and rules around business classes should be in the object metadata so that it shows up on both the client and the server automagically.
The most important thing to remember when doing these types of calculations is that:
1) Any code you send down to the client can be viewed by the client.
2) Any calculations done on the client could be (potentially) changed by the client.
So if you have an order service and calculate the order total only on the client, a malicious user could send you an order with a miscalculated total.