zoukankan      html  css  js  c++  java
  • WCF Data Services 基础

    把最近使用的WCF Data Service和WCF RIA Service的使用例子发布在站点http://dskit.codeplex.com , 本系列文章就把WCF Data Service和WCF RIA Service涉及的主要方面描述一下,希望通过这些内容,可以比较顺畅的把这些框架使用起来,以提高开发的效率。

    WCF Data Services中几个基础的概念

    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类型

    承载的服务可以以JSON和ATOM返回【请求时说明MIME类型】用的返回类型如下:

    MIME

    MIME Type

    应用程序类型

    JSON

    application/json

    ASP.NET, AJAX, Silverlight

    Atom

    application/atom+xml

    .NET Clients, Silverlight, ASP.NET mashups

    HTTP Operation Success Return Codes

    根据REST的定义对于不同的操作定义的服务端返回值情况:

    Operation Success Code

    GET 200 OK

    POST 201 Created

    PUT 204  No- Content

    DELETE 204  No- Content

    MERGE 204  No- Content

    简单例子

    VS2010中新建一个WEB工程,按如下步骤建立一个例子项目

    建立微软SQL例子数据库NorthWind

    1、  添加 Ado.net Entity: 选择SQL最初的例子NorthWind数据库

    2、  添加WCF Data Services:WcfDataService.svc

    3、  在WcfDataService.svc.cs配置访问规则:

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

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

                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;

    以上的部分是配置服务的可访问性和权限、行为等各种参数,具体参考MSDN,如果不对互联网公布的,默认配置也可

    4、服务访问测试:Build解决方案后即可访问

    下表是几个访问的实例

    发布的服务描述

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

    多个实体实例

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

    单个实体实例

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

    对象关系导航

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

    【工程可从http://dskit.codeplex.com下载】

    可以看到发布一个数据并进行查询等处理写的代码简直是很少了,而提供的功能却非常强大,后续对查询等继续进行说明。

  • 相关阅读:
    吴裕雄--天生自然C语言开发:共同体
    吴裕雄--天生自然C语言开发:结构体
    吴裕雄--天生自然C语言开发:字符串
    吴裕雄--天生自然C语言开发:函数指针
    吴裕雄--天生自然C语言开发:指针
    吴裕雄--天生自然C语言开发:enum(枚举)
    100个容器周边项目,点亮你的容器集群技能树
    论云时代最经济的APM工具的姿势
    “弹性裸金属服务器”到底有那些特性?
    弹性裸金属服务器服务于市场的技术概要分析
  • 原文地址:https://www.cnblogs.com/2018/p/1852579.html
Copyright © 2011-2022 走看看