WCF服务与WCF数据服务的区别

时间:2023-11-10 12:20:26

问:

Hi, I am newbie to wcf programming and a little bit confused between WCF Service and WCF Data  Service. Can someone please explain me these two service types. Can we use them alternatively or each one has its one well-defined specific area to use. Thanx in advance.

答:

WCF Services are operation centric - the main thing you do with these is define operations (functions). Data comes as a secondary thing in a way. On the other hand they can work over lot of different transports/protocols. You have the ability to strictly define what the client can and can not do. Client can't really make up new queries/operations, the server must implement everything the client needs.

WCF服务是以操作为中心的,你主要做的事情就是定义不同的操作(函数),数据放在一个次要的位置。另一方面,他们可以在许多不同的协议下工作。你可以严格的定义,客户端能做什么,不能做什么。客户端不能自己定义新的查询/操作,服务端必做实现客户端所要求的一切。

WCF Data Services are data centric - the main thing you do with these is define a data model to be exposed. Operations on the data are "predefined" (Create/Delete/Update/Read). It only supports HTTP protocol and uses REST. You usually allow clients to decide what they want to do (in some boundaries). One of the main differences from WCF Service is that the client can issue a query against the data model (think SQL like stuff) which the client constructs. This means that the server doesn't need to know exactly what the client needs up front, the client will be able to tell it runtime.

WCF数据服务是以数据为中心。你主要做的事情就是定义一个数据模型,并暴露出去。对数据的操作是“预定义”(创建/删除/更新/读取)。它仅支持HTTP协议和使用REST。允许客户端来决定他们想要做什么(在某些界限下)。一个与WCF服务的主要区别是,客户端可以对数据模型发起一个类型SQL的查询。这意味着服务端并不需要预先知道客户的需要,客户端将能够在运行时告诉它。

问:

Thanx for your response. It clears confusion i had in my mind. I appreciate if u please answer my following questions to further clarify the concepts.

  1. Can I use both wcf service and data service in a single service. I mean using single service reference.
  2. Can I add business logic in CRUD operations.
  3. Can I create service operations in wcf data service similar to what I can create in WCF service. (What I know is in wcf data service i can create service operations but they are very limited and allows only primitive data types as parameters.

Thanks

答:

Hi,

1. No - WCF Services and WCF Data Services need to be exposed as two different endpoints currently and as a result you need to service references on the client. The other reason is that the client classes generated for them are quite different and currently would not work together.

2. You can add bussiness logic to CRUD operations in general. The limitations depend on the actual provider and implementation of the WCF Data Service. Without knowing your requirements on what the bussiness logic should do and what provider you're going to use it's very hard to tell yes or no.

3. Service operations in WCF Data Services are indeed limited. You can't get the full power of WCF Services here.

Thanks,

原文地址:http://social.msdn.microsoft.com/Forums/en-US/687426d9-709f-4e73-8c4c-dd3630f006e7/wcf-data-service-or-wcf-service?forum=adodotnetdataservices