[转]WCF Data Services OData
http://martinwilley.com/net/data/wcfds.html
WCF Data Services
About
Formerly "Astoria" and "ADO.Net Data Services", this is the .Net ODATA implementation - ODATA being RESTful HTTP/JSON/ATOM xml access to databases.
OData
HTTP verbs: GET is get, POST is insert, PUT is update, MERGE is partial update, DELETE is delete
NB: PUT,MERGE and DELETE may be blocked by proxies/firewalls, so add the X-HTTP-Method header can be added to a POST request
- Use http://localhost/wcfds.svc/$metadata to get metadata (like ?wsdl)
- http://localhost/wcfds.svc/customers('ALFKI')
get by primary key - http://localhost/wcfds.svc/customers/$count
- http://localhost/wcfds.svc/customers?$orderby=Price desc
- http://localhost/wcfds.svc/customers?$skip=20&$top=5
- http://localhost/wcfds.svc/customers?$filter= Name eq 'Bill' and Price gt 10
- http://localhost/wcfds.svc/customers?$filter= startswith(name, 'B') and year(Date) gt 2011 and round(Price) = 5
- http://localhost/wcfds.svc/customers?$expand=Orders/Order_Details
Eager loading
Server code
Reference System.Data.Services.Client.dll. The VS2010 item template for the endpoint is "WCF Data Service". The svc code behind is a DataService<T> with a static InitializeService() method which should expose a IQueryable<T> getter.
DataService<T> can be an Entity Framework ObjectContext, which exposes the ObjectSets (tables).
For custom classes that are exposed, add a [DataServiceKeyAttribute(pk)] to the class to denote the primary key (for http://localhost/wcfds.svc/custom('ALFKI') gets). For POCOs, add [DataContract(IsReference=true)] so properties are serialized as objects, not values (i.e. product.Category refers to a Category object).
Security
You can secure with the standard IIS/web.config settings including Windows, asp.net forms etc.
In the client library, you can set context.Credentials = new NetworkCredential(username, password) or use the context.SendingRequest event to set request headers such as Authorization.
In server InitializeService, configure SetEntitySetAccessRules
Service Operations
In InitializeService, config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); as applicable/
Expose sprocs as service operations: [WebGet]/[WebInvoke] methods- input parameters must be primitives, return must be primitive or IEnumerables/IQueryable.
Client
Adding a service reference to an ODATA service creates a proxy derived from DataServiceContext which looks like a normal EF ObjectContext. (MSDN concepts)
- context.SaveChanges(SaveChangesOption.Batch) will batch changes (also: ContinueOnError, ReplaceOnUpdate)
Catch DataServiceQueryException, DataServiceRequestException - It uses ATOM - to use JSON, use a WebClient with client.Headers["Accept"] = "application/json"
- In a partial class, add [QueryInterceptor("Customers")]public Expression... OnQueryCustomers()
- [ChangeInterceptor("Customers")] can also be used for validation (or subscribe to regular EntityChanging event)
For data-binding, wrap the objectsets in DataServiceCollection which extends ObservableCollection.
Queries
- The entity collections (ObjectSets in EF) are DataServiceQuery<T> but otherwise it's mostly normal IQueryable
- Eager load (ODATA $expand) with context.Orders.Expand("Order_Details")
- Explicit load (lazy load) with context.LoadProperty(order, "Order_Details")
- Explicitly executing the query returns a QueryOperationResponse.
When paging, this has a GetContinuation property which includes the url of the next page
NB: you must iterate the query result to use the continuation
[转]WCF Data Services OData的更多相关文章
- 为 Oracle Database 开发 WCF Data Services 和 OData 应用程序
为 Oracle Database 开发 WCF Data Services 和 OData 应用程序 本教程包含以下部分: 目的 所需时间 概述 先决条件 创建新的网站项目 ...
- WCF Data Services 5.0 for OData V3
https://www.microsoft.com/en-us/download/details.aspx?id=29306 VS 2010 下 安装 WCF Data Services 5.0 en ...
- [转]Consuming a OData Service in a Client Application (WCF Data Services)
本文转自:https://msdn.microsoft.com/zh-tw/library/dd728282(v=vs.103).aspx WCF Data Services 5.0 其他版本 ...
- [转]访问 OData 服务 (WCF Data Services)
本文转自:http://msdn.microsoft.com/zh-SG/library/dd728283(v=vs.103) WCF 数据服务 支持开放式数据协议 (OData) 将数据作为包含可通 ...
- 精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性
[索引页][源码下载] 精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性 作者:weba ...
- 【2016-10-26】【坚持学习】【Day13】【WCF】【EF + Data Services】
今天做了一个demo, EF+Data Services 先建立一个网站项目 添加一个ADO.NET 数据模型 相当于一个EF容器,用来连接MSSQL数据库 添加一个WCF Data Services ...
- WCF Data Service 使用小结 (一)—— 了解OData协议
最近做了一个小项目,其中用到了 WCF Data Service,之前是叫 ADO.NET Data Service 的.关于WCF Data Service,博客园里的介绍并不多,但它确实是个很好的 ...
- WCF Data Service 使用小结 —— 了解OData(一)
最近做了一个小项目,其中用到了 WCF Data Service,之前是叫 ADO.NET Data Service 的.关于WCF Data Service,博客园里的介绍并不多,但它确实是个很好的 ...
- WCF Data Service 使用小结(二) —— 使用WCF Data Service 创建OData服务
在 上一章 中,介绍了如何通过 OData 协议来访问 OData 服务提供的资源.下面来介绍如何创建一个 OData 服务.在这篇文章中,主要说明在.NET的环境下,如何使用 WCF Data Se ...
随机推荐
- Sql Server中的事务隔离级别
数据库中的事物有ACID(原子性,一致性,隔离性,持久性)四个特性.其中隔离性是用来处理并发执行的事务之间的数据访问控制.SqlServer中提供了几种不同级别的隔离类型. 概念 Read UnCom ...
- docker基于commit命令创建支持ssh服务的镜像
以centos为基础,目的使用ssh服务远程连接docker容器. 环境:宿主机centos7(宿主机ip地址为192.168.164.130),直接搜索docker的centos镜像,下载最新版本. ...
- SQL Server 查询优化器运行方式
一.结合实际,谈索引使用的误区 理论的目的是应用.虽然我们刚才列出了何时应使用聚集索引或非聚集索引,但在实践中以上规则却很容易被忽视或不能根据实际情况进行综合分析.下面我们将根据在实践中遇到的实际问题 ...
- 关于centos6升级python3.6无法使用pip的问题
用find / -name "pip",也找不到类似/usr/bin/pip类似的命令,说明pip没安装好,那么运行下面的命令 yum install python-pip 然后可 ...
- 细说Cookie(转)
原文地址:http://www.cnblogs.com/fish-li/archive/2011/07/03/2096903.html#undefined Cookie虽然是个很简单的东西,但它又是W ...
- 解决 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 问题(转载)
最近新装好的mysql在进入mysql工具时,总是有错误提示:# mysql -u root -pEnter password:ERROR 1045 (28000): Access denied fo ...
- 分布式锁实践(二)-ZooKeeper实现总结
写在最前面 前几周写了篇 利用Redis实现分布式锁 ,今天简单总结下ZooKeeper实现分布式锁的过程.其实生产上我只用过Redis或者数据库的方式,之前还真没了解过ZooKeeper怎么实现分布 ...
- Java并发编程-Thread类的使用
在前面2篇文章分别讲到了线程和进程的由来.以及如何在Java中怎么创建线程和进程.今天我们来学习一下Thread类,在学习Thread类之前,先介绍与线程相关知识:线程的几种状态.上下文切换,然后接着 ...
- selenium+python自动化79-文件下载(SendKeys)
前言 文件下载时候会弹出一个下载选项框,这个弹框是定位不到的,有些元素注定定位不到也没关系,就当没有鼠标,我们可以通过键盘的快捷键完成操作. SendKeys库是专业的处理键盘事件的,所以这里需要用S ...
- django-常用过滤器
django常用过滤器 add :字符串相加,数字相加,列表相加,如果失败,将会返回一个空字符串. default:提供一个默认值,在这个值被django认为是False的时候使用.比如:空字符串.N ...