MVVM与 WCF - 视图模型和模型关系
我不明白我的模型如何成为 WCF 服务。 当 Astoria 分部类驻留在客户端上并允许远程调用执行持久性调用时,这是有意义的,但 WCF 服务没有可用于更新数据存储的模型字段的属性。
即使我可以将模型/域对象类的接口分解为单独的程序集,silverlight 项目也不允许我将其添加为引用。
我的 ViewModel 应如何包含我的 WCF 调用? 最终,WCF 将调用在 Linq-to-Sql 中实现的存储库程序集,但显然这些实体不是我在这种情况下的模型,我的 WCF 类是吗?
感谢您对此的任何指导。
另外,我读过的帖子提供了参考框架:
I am not understanding how my model can be a WCF service. It makes sense when its an Astoria partial class residing on the client that allows remote calls to do persistence calls, but a WCF service doesn't have properties for model fields that can be used to update a data store.
Even if I could factor out an interface for a model/domain object class into a separate assembly, a silverlight project will not allow me to add that as a reference.
How should my ViewModel encompass my WCF calls? Ultimately the WCF will call a repository assembly implemented in Linq-to-Sql, but apparently those entities are not my model in this scenario, my WCF classes are?
Thanks for any guidance on this.
Also, posts I have read to give a frame of reference:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在 Silverlight 项目中创建对 WCF 服务的服务引用时,它还会生成该服务的接口,这类似于上面列出的文章中的 David Wynns IFeedService。 服务引用还将生成代表服务使用的对象(产品、类别等)的代理对象。
需要注意的重要一点是,服务接口不是模型,而是访问模型的方式。 回到 David 的示例,他的 ViewModel 公开了一个项目列表(他的模型),该列表是使用服务检索的。
如果您希望在客户端和服务器之间共享代码,我建议您研究 RIA 服务之类的东西。 如果这不适合您,那么我会看一些有关在服务器和客户端之间共享代码的文章(通过添加为链接)。
希望这可以帮助
When you create a service reference to a WCF service in a Silverlight project it also generates an interface for that Service, this is similar to David Wynns IFeedService in the articles you listed above. The service reference will also generate proxy objects that represent the objects used by the service (Product, Category etc).
The important thing to note is that the service interface isn't the model, it's how you access the model. Going back to David's example, his ViewModel exposes a list of items (his model), this list is retrieved using the service.
If you're looking to share code between the client and server I'd reccomend looking into something like RIA Services. If this isn't for you then I'd look at a few articles around about sharing code between the server and client (via Add as Link).
Hope this helps