天天看點

WCF服務與WCF資料服務的差別

問:

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

如果我的文章對你有幫助,就點一下推薦吧.(*^__^*)

wcf

繼續閱讀