日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WCF Data Services 基础

發(fā)布時(shí)間:2025/3/8 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WCF Data Services 基础 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

把最近使用的WCF Data Service和WCF RIA Service的使用例子發(fā)布在站點(diǎn)http://dskit.codeplex.com , 本系列文章就把WCF Data Service和WCF RIA Service涉及的主要方面描述一下,希望通過這些內(nèi)容,可以比較順暢的把這些框架使用起來,以提高開發(fā)的效率。

?

WCF Data Services中幾個(gè)基礎(chǔ)的概念

Tenets of REST

  • HTTP method

?Method information is kept in the HTTP header, not in the body of the request.

  • Resource based

?Resources are expressed as “services” that clients consume.

  • Addressability

The scoping information is kept in the URL. ?Operations such as $filter $top $skip

  • Relationships

How the data relates to each other is expressed in ADO.NET Data Services by resource links according to the CSDL [ specified in the Entity Data Model (EDM)]. A relationship link element such as <link href=”Customers(‘ALFKI’)/Orders

  • Statelessness

No stateful messages are exchanged between resources

MIME類型

承載的服務(wù)可以以JSON和ATOM返回【請求時(shí)說明MIME類型】用的返回類型如下:

MIME

MIME Type

應(yīng)用程序類型

JSON

application/json

ASP.NET, AJAX, Silverlight

?

Atom

application/atom+xml

.NET Clients, Silverlight, ASP.NET mashups

HTTP Operation Success Return Codes

根據(jù)REST的定義對于不同的操作定義的服務(wù)端返回值情況:

Operation Success Code

GET 200 OK

POST 201 Created

PUT 204? No- Content

DELETE 204? No- Content

MERGE 204? No- Content

簡單例子

VS2010中新建一個(gè)WEB工程,按如下步驟建立一個(gè)例子項(xiàng)目

?

建立微軟SQL例子數(shù)據(jù)庫NorthWind

1、? 添加 Ado.net Entity: 選擇SQL最初的例子NorthWind數(shù)據(jù)庫

2、? 添加WCF Data Services:WcfDataService.svc

3、? 在WcfDataService.svc.cs配置訪問規(guī)則:

????????????config.SetEntitySetAccessRule("*",?EntitySetRights.AllRead);

????????????config.SetServiceOperationAccessRule("*",?ServiceOperationRights.All);

????????????config.DataServiceBehavior.MaxProtocolVersion?=?DataServiceProtocolVersion.V2;

以上的部分是配置服務(wù)的可訪問性和權(quán)限、行為等各種參數(shù),具體參考MSDN,如果不對互聯(lián)網(wǎng)公布的,默認(rèn)配置也可

?

4、服務(wù)訪問測試:Build解決方案后即可訪問

下表是幾個(gè)訪問的實(shí)例

發(fā)布的服務(wù)描述

http://localhost:1206/WcfDataService.svc/

多個(gè)實(shí)體實(shí)例

http://localhost:1206/WcfDataService.svc/Suppliers

單個(gè)實(shí)體實(shí)例

http://localhost:1206/WcfDataService.svc/Suppliers(1)

對象關(guān)系導(dǎo)航

http://localhost:1206/WcfDataService.svc/Suppliers(1)/Products

【工程可從http://dskit.codeplex.com下載】

?

可以看到發(fā)布一個(gè)數(shù)據(jù)并進(jìn)行查詢等處理寫的代碼簡直是很少了,而提供的功能卻非常強(qiáng)大,后續(xù)對查詢等繼續(xù)進(jìn)行說明。

總結(jié)

以上是生活随笔為你收集整理的WCF Data Services 基础的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。