[转]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 ...
随机推荐
- oracle的热备份和冷备份
一.冷备份介绍: 冷备份数据库是将数据库关闭之后备份所有的关键性文件包括数据文件.控制文件.联机REDO LOG文件,将其拷贝到另外的位置.此外冷备份也可以包含对参数文件和口令文件的备份,但是这 ...
- 内核程序开发 LED灯顺序点亮、顺序熄灭
根据实际考试情况,你要按顺序这么来干. 首先,把老师给的文件1.LED灯顺序点亮.顺序熄灭导入到虚拟机里你喜欢的目录下 进入此目录1.LED灯顺序点亮.顺序熄灭: 看到这三个文件,依次打开背过,老师出 ...
- [Python] numpy.sum
import numpy as np #Syntax: numpy.sum(a, axis=None, dtype=None, out=None, keepdims=<class numpy._ ...
- ubuntu sudo apt-get update与sudo apt-get upgrade的作用及区别,以及python pip的安装
在UBUNTU下,我们维护一个源列表,源列表里面都是一些网址信息,这每一条网址就是一个源,这个地址指向的数据标识着这台源服务器上有哪些软件可以安装使用.编辑源命令: sudo gedit /etc/a ...
- 常用的ubantu操作命令
Ubuntu软件操作的相关命令 sudo apt-get update 更新源 sudo apt-get install package 安装包 sudo apt-get remove package ...
- Selenium Webdriver——处理Table
html table是由 table 元素以及一个或多个 tr.th 或 td 元素组成.如下: HTML源码如下: <html> <head> <meta http-e ...
- spring jpa sqls
package com.example.repository; import java.util.List; import org.springframework.data.jpa.repositor ...
- 关于std:auto_ptr std:shared_ptr std:unique_ptr
很多人听说过标准auto_ptr智能指针机制,但并不是每个人都天天使用它.这真是个遗憾,因为auto_ptr优雅地解决了C++设计和编码中常见的问题,正确地使用它可以生成健壮的代码.本文阐述了如何正确 ...
- 解决SQL将varchar值转换为数据类型为int的列时发生语法错误
今天遇到一个这样的错误,具体的报错情况如下 解决的方案如下. 数据库MSSQL在比较大小时,出错提示:“将 varchar 值 '24.5' 转换为数据类型为 int 的列时发生语法错!”分析数据库设 ...
- 【327】Python 中 PIL 实现图像缩放
参考:Python 中使用PIL中的resize 进行缩放 参考:Python用Pillow(PIL)进行简单的图像操作(模糊.边缘增强.锐利.平滑等) 参考:廖雪峰 - Pillow 实现代码如下: ...