wcf 和 knockout.js 结合

发布于 2024-12-22 19:01:39 字数 604 浏览 1 评论 0原文

我准备好了数据层、业务层。现在我想实现服务层。 我不想在 wcf ria 服务中实现这一层。有没有其他方法可以使用wcf这样的方式实现这一层,以便我使用js通过wcf获取我的模型。 例如,我有我的域名“Person”。 (在域项目中)。然后在我的“PersonRespository”中有 InsertPerson、GetPerson 等用于获取“Person”并将其存储在数据库中。

现在我想使用 asp.net mvc 来显示人员详细信息。

因此,接下来的两层将是表示层和服务层,并使用 knockout.js 在客户端操作数据,我陷入了以下问题。

  1. 我的表示层将在哪里。我正在使用 asp.net mvc,所以它应该位于 mvc 应用程序的模型文件夹中,是否明智地将相同的代码类(Person)也从域模型复制到模型文件夹中。当它们相同时发生事件。

  2. 我将如何能够在 javascript 中获取“Person”模型类,并能够将其从 javascript 更新到数据库。

我的架构风格是企业级的还是我遗漏了一些东西。

任何教程都会有帮助。

如果您还有任何疑问,请告诉我。

谢谢,

达尔吉特

I got my datalayer, business layer ready. Now i want to to implement service layer.
I do not want to implement this layer in wcf ria services. Is there any other way to implement this layer in such a way using wcf, so that I get my model through wcf using js.
For example I have my domain 'Person'. (In domain project). Then in my 'PersonRespository' has
InsertPerson, GetPerson etc. to get and store the 'Person' in database.

Now I want to use asp.net mvc to show the person detais.

So next two layer will be Presentation Layer and service layer and manipulate data on client side using knockout.js and I am stuck on following issues.

  1. Where will be mine Presentation layer will live. I am using asp.net mvc so It should be in model folder of mvc application, Is it wise to copy the same code class (Person) to model folder as well from domain model. Event when they are same.

  2. How I will be able to get 'Person' model class in javascript and able to update it from javascript to database as well.

Is my architecture style is of enterprise level or i am missing something.

Any point to tutorial will be helpful.

If you have any further questions please let me know.

Thanks,

Daljit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡忘如思 2024-12-29 19:01:39

问题 1:

不,你不应该重复你的代码。在 DRY (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself) 开发原则中对此进行了讨论。

问题 2:

建议您使用 json 序列化器序列化您的模型并将其发送到您的 UI。它将被更新等,然后发送回服务。 Google Javascript 中的 MVVM 模式,看看这是如何完成的。 KnockoutJs 是实现您想要的目标的良好开端。最好查看在knockoutjs 中完成的一些示例,看看发生了什么。 MVVM for WPF 中还有许多示例,可能有助于在更高层次上理解该模式。我建议您访问 codeproject.com 了解深入的 MVVM 示例。

就您的层而言,您有很多选择,但一般建议是:

1) 演示必须通过 MVVM 绑定触发,即如果绑定更新,UI 将自行更新。
2) asp.net 方面应该仅在通过 ajax 向 UI 发送更新时更新模型。 (并非所有内容都需要通过 ajax 发送,我不是这么说的。当它这样做时,它不应该发送额外的 html 或 js 来放入页面中)。
3) 你的模型应该真正来自asp.net 到html 页面。 (这将使以后的事情变得更容易,因为页面只会通过 ASP.NET 模型进行更新,并且您不会获得来自多个域的项目,这最终会带来麻烦。
4) 您的 asp.net 站点应该为您的 WCF 服务提供包装器,并且可以将调用转发到 WCF。

或者

如果您不想用 asp.net 包装 WCF,并且需要您的 UI 通过 ajax 直接与 WCF 通信(应该是一个更罕见的用例,例如使用小部件执行类似 igoogle 的页面,或者可能是没有 asp.net 交互的移动开发,即完整的 js 应用程序)然后您可以研究 CORS 作为从 JS 到 WCF 以及 JS 到 asp.net 的选项(这是一个困难的困难,易于编程,很难为 WCF 工作,因为有很多对于我来说非 IIS 托管的 WCF,其相关文档非常少)。请参阅此页面了解信息:http://enable-cors.org/

Question 1:

No you should not be repeating your code. There is talk about this in the DRY (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself) principals of development.

Question 2:

It is recommended that you serialize your model using a json serializer and send it to your UI. It will be updated etc, and then sent back to the services. Google MVVM pattern in javascript to see how this is done. KnockoutJs is a great start in achieving what you want. Its probably best to check out some examples done in knockoutjs to see what is going on. There are also many examples in MVVM for WPF that might help understanding the pattern at a higher level. I would recommend seeing codeproject.com for indepth MVVM examples.

As far as your layers go, you have many options, but a generic recommendation would be:

1) Presentation must be triggered through MVVM bindings, ie if the binding updates, the UI will then update itself.
2) the asp.net side of things should only update the models when sending updates via ajax to the UI. (not everything needs to be sent via ajax, im not saying that. When it does, it shouldn't also send extra html or js to put in the page).
3) Your models should really come from asp.net to the html page. (this will make things easier later, as the page will only be updated via asp.net models and you won't get items coming from multiple domains, which ends up being a nuisance.
4) Your asp.net site should provide a wrapper for your WCF service, and can foward calls to WCF.

OR

If you didn't want to wrap WCF with asp.net and needed your UI to communicate directly via ajax to WCF (should be a rarer usecase like doing an igoogle like page with widgets, or maybe mobile development with no asp.net interaction, ie full js app) Then you can investigate CORS as an option to go from JS to WCF and JS to asp.net (This is of a hard difficulty, easy to program, hard to get working for WCF as there is very very low documentation on it for in my case non IIS hosted WCF). See this page for information: http://enable-cors.org/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文