[英]WCF and Entity Framework . How to Create a Service Layer for all entities - Generically
Ok so I am a bit lazy here. 好的,所以我在这里有点懒。 I want a Generic WCF service Layer to support my database functionality.
我希望通用WCF服务层支持我的数据库功能。 I have a repository pattern for DB access - but in WCF from what I am reading it seems if I want to access each of these Entities - I need to create a Service Contract for each entity (I guess multiple endpoints.) As I do not want multiple hosts.
我有一个用于数据库访问的存储库模式-但是从WCF看来,如果我想访问这些实体中的每个实体,则需要为每个实体创建服务合同(我想有多个端点)。想要多个主机。 WCF Data Services only supports webHTTPBinding and not Net.Tcp Binding.
WCF数据服务仅支持webHTTPBinding,不支持Net.Tcp绑定。 The DAL EF data POCO's are shared between client and service host.
客户端和服务主机之间共享DAL EF数据POCO。 So is it possible to use Generics since the types are shared in both client and server?
因为类型在客户端和服务器中共享,所以可以使用泛型吗? If so a small simple example should be enough to get me on my way.
如果是这样的话,一个简单的例子就足以让我步入正轨。
Basically what you need to do here is break everything down into seperate libraries. 基本上,您需要在此处将所有内容分解为单独的库。 You need to create seperate classes for the Service Contract, Service Interface, Data Layer and a Data Transfer Objects library.
您需要为服务合同,服务接口,数据层和数据传输对象库创建单独的类。
You do this so that the Service Interface library can be shared on the client side and used to build a proxy using the ChannelFactory object and being passed a reference to the interface. 这样做是为了可以在客户端共享服务接口库,并使用ChannelFactory对象将其传递给接口引用,以用于构建代理。 (Dont use the "Add Service Reference" option in Visual Studio - build it yourself manually)
(不要在Visual Studio中使用“添加服务引用”选项-自己手动构建)
Doing this will enable to customise the proxy creation. 这样做可以自定义代理创建。 What you cant do is make generic functions to access the service methods since the whole point of SOAP and WCF is that the methods form a solid contract between client and server.
您不能做的是使通用函数访问服务方法,因为SOAP和WCF的全部要点是,这些方法在客户端和服务器之间形成了牢固的契约。 However, doing it this way will at least provide you with a way of sharing some of the burden between client and server in terms of code writing.
但是,这样做至少可以为您提供一种在代码编写方面分担客户端和服务器之间的负担的方法。
Miguel Castro offers up a good article here that explains the method: www.codemag.com/article/0809101 Miguel Castro在这里提供了一篇很好的文章来说明方法:www.codemag.com/article/0809101
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.