ADO.NET 4 快速上手(11)——WCF Data Service提供基于REST的服务(完)

来源:互联网 发布:上海网络 编辑:程序博客网 时间:2024/05/16 18:33

十一、    WCF Data Service提供基于REST的服务

生成的服务类代码,修改两处:

// 泛型为实体模型public class UserDataService : DataService<UserEntities>{    public static void InitializeService(DataServiceConfiguration config)    {        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;        // 设置读取权限        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);    }}

运行程序:

地址(假设端口为55863)

结果

http://localhost:55863/UserDataService.svc/

AtomPub格式服务可用功能的信息

http://localhost:55863/UserDataService.svc/tb_User

加实体名,返回所有实体

http://localhost:55863/UserDataService.svc/tb_User('Jack')

加主键,返回唯一实体。主键若为字符串,加单引号;若为64位长整数,以大写“L”结尾,如:3L。

http://localhost:55863/UserDataService.svc/tb_User('Jack')/password

导航属性

http://localhost:55863/UserDataService.svc/tb_User?$orderby=Username

http://localhost:55863/UserDataService.svc/tb_User?$orderby=Username desc

排序



至此,本系列文章完,十分感谢阅读,也欢迎和我交流!

原创粉丝点击