Microsoft Press Windows Azure Step by Step Note
来源:互联网 发布:福彩三地九宫图算法 编辑:程序博客网 时间:2024/05/22 01:59
WCF Data Services and OData
Open DataProtocol (OData) is an emerging protocol for querying and updating data across
the web. Ituses existing technologies such as HTTP, JSON (JavaScript Object Notation), and
AtomPublishing Protocol (AtomPub) to provide abstract access to a variety ofservices,
stores,applications, and data.
Exposing data using OData protocol
WCF DataService (providers : Entity Data Model)
1.Use theAdd New Item wizard to add a WCF Data Service
2.publicclass EstatesManagement : DataService<Entities>
{...
publicstatic void InitializeService(DataServiceConfiguration config)
{
// TODO: setrules to indicate which entity sets and service
operationsare visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*",EntitySetRights.All);
config.SetServiceOperationAccessRule("*",
ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion=
DataServiceProtocolVersion.V2;
}
http://msmvps.com/blogs/siva/archive/2010/11/04/exposing-data-via-odata.aspx
With WCFData Services (DS for short), providing data using OData is simple and easytoo. Out of the box, DS can pull data in two ways and expose it as one or more feeds:
ADO.NETEntity Framework - DS integrates with ADO.NET Entity Framework (EF) well and assuch it can provide an OData layer on top of an existing EF model and exposedata from the underlying relational database. In this way, each entity in themodel may be given a unique URI by DS and exposed as a feed (in OData terms,Entity Set - collection of business entities). The advantage with this is that DS itself gives the plumbing for CRUD operations that you may want to performon the entities exposed.
Plain .NETclasses - Lets you expose plain .NET classes as WCF Data Services. For exampleyou can expose your plain-old-C#-class (POCO) libraries as OData feeds simplyusing DS.Behind the scenes, DS uses .NET reflection to detect IQueryablecollections on a target class and exposes them as feeds. The advantage is thatyou have better control over the actual CRUD operations when invoked via HTTP.The downsides are many:
Obviously,you have to write extra code to expose your object collection asIQueryable.
DS supportsonly Select operation by default for this type of data source and Atomformatted output.If you want to provide Update, Delete and Insert operationsas well on the feeds then you should implementIUpdatable interface.
OnlyAtom-formatted results are supported. If you need JSON-formatted response, youhave to again write more code.
[DataServiceKey("LawyerID")]
public classLawyerInfo
{
public int LawyerID {get; set;}
public string Name {get; set;}
public string OfficeCode {get; set;}
public AddressInfo Address {get; set;}
}
[DataServiceKey("AddressID")]
public classAddressInfo
{
public int AddressID {get; set;}
public string AddressLine {get; set;}
public string City {get; set;}
public string State {get; set;}
}
public classLawyerDataProvider
{
private static List<LawyerInfo> _ds;
public LawyerDataProvider ()
{
_ds = new List<LawyerInfo> ();
_ds.Add (new LawyerInfo ()
{
LawyerID = 89,
Name = "James Horner",
OfficeCode = "NY921",
Address = new AddressInfo ()
{
AddressID = 8,
AddressLine = "100 ParkAve",
City = "New York",
State = "NY"
}
});
_ds.Add (new LawyerInfo ()
{
LawyerID = 61,
Name = "Mathew Perry",
OfficeCode = "IL017",
Address = new AddressInfo ()
{
AddressID = 15,
AddressLine = "625 WestMadison",
City = "Chicago",
State = "IL"
}
});
_ds.Add (new LawyerInfo ()
{
LawyerID = 17,
Name = "Samatha Mathis",
OfficeCode = "NJJC",
Address = new AddressInfo ()
{
AddressID = 35,
AddressLine = "JournalSquare",
City = "Jersey City",
State = "NJ"
}
});
}
public IQueryable<LawyerInfo> Lawyers
{
get {return_ds.AsQueryable<LawyerInfo>();}
}
}
public classLawyerDs : DataService<LawyerDataProvider>
{
public static voidInitializeService(DataServiceConfiguration config)
{
config.DataServiceBehavior.MaxProtocolVersion= DataServiceProtocolVersion.V2;
config.SetEntitySetAccessRule("Lawyers", EntitySetRights.All);
}
}
- Microsoft Press Windows Azure Step by Step Note
- MS Press - Microsoft ADO.NET Step by Step
- Microsoft Windows Vista Step by Step
- Microsoft.Press.Microsoft.Expression.Web.Step.by.Step.Nov.2007.eBook-BBL
- Microsoft Silverlight4 step by step
- 书讯 -- Microsoft Windows Workflow Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 书讯 -- Microsoft Windows Workflow Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 书讯 -- Microsoft Windows Workflow Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 书讯 -- Microsoft Windows Workflow Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 书讯 -- Microsoft Windows Workflow Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 书讯--Microsoft Windows Communication Foundation Step by Step
- 《C语言接口与实现》读书疑问1(2012.06.03已解决)
- 控制上网!!!(版本之1.1) 当前时间从网络取得。
- python官方网站的下载链接竟然特意使用了中文标示“下载” (for china)
- 1/29/2012
- Flex程序启动过程再探秘: (1)基础知识
- Microsoft Press Windows Azure Step by Step Note
- c语言中的变量(局部变量,外部变量,静态变量,寄存器变量)
- 【算法设计与分析】最大子段和问题
- 第十一周报告二之英寸向米的转换表
- cocos2d-x初探学习笔记(13)--内存回收机制
- cocos2d-x初探学习笔记(14)--菜单项
- 平凡而又神奇的贝叶斯方法
- 愤怒,当伴娘闹洞房被扒光上衣
- 安装EHLib