这种设计方法应该保留什么 [英] What should keep into this design approach
问题描述
我的项目解决方案如下:
My Project solution is as below:
- MVC项目(包含下面列出的两个项目的参考)
- 包含业务方法的WCF服务(包含下列项目的引用)
- DTO或BusinessOBject的公共项目
IN MVC-调用WCF服务方法如下- IList< Employee> RetriveData()
从MVC调用-ServiceClient.RetrieveData(),现在问题是返回对象 Employee
指向 ServiceHost.Employee
对象而不是- Common.DTO.Employee
对象(库项目),因此会产生类型转换错误。
IN MVC - Calling the WCF service method is as follow - IList<Employee> RetriveData()
it is called from MVC - ServiceClient.RetrieveData() , now problem is return object Employee
point to ServiceHost.Employee
object instead of - Common.DTO.Employee
object (Library project) so, it gives type casting error.
任何人都可以建议我这里的解决方案是什么,或者我应该从MVC中删除 Common.DTO项目推荐人,而只能使用 Servicehost.Employee
对象。
Can any one suggest me what is the solution over here or i should remove "Common.DTO" project refernece from MVC and only use Servicehost.Employee
object.
请指导我如何使用此设计。
Please guide me on this design, what should use.
注意:所有对象均为DATACONTRACT(可序列化)。
在MVC应用程序中,在检索DTO对象之后,我确实将它们转换为Viewmodel(它还在内部引用任何集合对象,例如 IList< ServiceHost.LookupItem>
。可以直接使用所有生成的序列化对象或,是否必须将每个返回对象转换/转换为 common.DTO。
对象,然后转换为ViewModel?
NOTE: all objects are DATACONTRACT (serilizable).
In MVC applicaiton, after retrieing DTO object, i do convert them into Viewmodel (It also internally refer any collection object like IList<ServiceHost.LookupItem>
. Does it ok to use all generated serilized object directly OR , do i have to convert/cast each return object into common.DTO.
object and then convert into ViewModel ?
谢谢
推荐答案
不要使用 Visual Studio的 添加服务参考。这样做会导致在解决方案中定义了多种类型,而在客户端的客户端代理时间会变得不同步。
Don't use Visual Studio's Add Service Reference. Doing so will result in multiple types being defined in the solution and client-proxies that over time will become out of sync.
最好定义整个解决方案使用的通用合同程序集。
It is much better to define a common contracts assembly that your whole solution uses.
请参阅 WCF手动方法…正确方法 特别是第3页
Please see WCF the Manual Way…the Right Way specifically page 3
您应该尽可能遵循规范的数据模型之类的模式。这意味着POCO ORM的类型相同; WCF;并作为视图模型中的集合。数据转换很昂贵;导致增加的维护和可能的保真度损失。 http://www.soapatterns.org/ http://www.eaipatterns.com/
You should try to follow patterns such as canonical data model whenever possible. This means the same type for POCO ORM; WCF; and as aggregates in your view model. Data conversion is expensive; leads to increased maintenance and possible fidelity loss. http://www.soapatterns.org/ http://www.eaipatterns.com/
这篇关于这种设计方法应该保留什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!