用于对资源进行寻址的 URI 格式(ADO.NET 数据服务框架)

ADO.NET 数据服务中所有可访问的实体都可以通过 URI 进行寻址。ADO.NET 数据服务 URI 符合一般 URI 语法并使用超文本传输协议 (HTTP)。ADO.NET 数据服务 URI 由以下三个部分组成:服务根、资源路径和查询选项。这三部分可构成用于对 ADO.NET 数据服务中的任何资源进行寻址的 URI。

服务根

URI 的服务根部分表示 ADO.NET 数据服务的根位置。与 ADO.NET 数据服务的根关联的资源描述该服务的所有 EntitySetAssociationSet 和/或服务操作。以下是仅包含方案和服务名称元素的有效 URI:

  • https://www.contoso.com

  • http://::1:8080/myservice.svc

  • https://www.contoso.com/path/myservice.svc/

资源路径

URI 的资源路径元素指示可以如何组合实体集、实体类型、导航属性、导航链接、属性、复杂类型和服务操作名称,以生成一个用于标识 ADO.NET 数据服务中的资源的 URI。

URI 的资源路径元素允许筛选和遍历数据服务中的实体关系图。此部分不包括用于将针对请求的响应格式更改为指定的 URI 的任何构造。有关更改响应格式的信息,请参见ADO.NET 数据服务查询选项

以下是包含架构、服务根和资源路径元素的有效 URI:

  • https://www.contoso.com/myservice.svc/Customers

  • https://www.contoso.com/Customers(123)

  • https://www.contoso.com/Customers(123)/Orders

  • https://www.contoso.com/Customers(123)/$links/Orders

  • https://www.contoso.com/Products(ID=’ABC’)/Category

  • https://www.contoso.com/Teams(Conference=’ACC’, League=’NCCC’)/Roster

有关资源路径语法的更多信息,请参见资源路径规则和语义(ADO.NET 数据服务框架)

查询选项

URI 的查询选项部分指定了两类信息:系统查询选项和服务操作参数。查询选项符合以下规则:

  • 可以在单个 URI 查询字符串中指定任意数目的受支持的查询选项。

  • 在查询字符串中,每个查询选项可以独立于任何其他选项存在。

  • URI 中的查询选项的顺序并不重要。

  • 查询选项名称区分大小写。

  • 查询选项值区分大小写。

  • 在请求 URI 的查询字符串中,特定的系统查询选项只能出现一次。

有关查询语义的更多信息,请参见ADO.NET 数据服务查询选项ADO.NET 数据服务系统查询选项

示例

以下 URI 是 ADO.NET 数据服务语法的示例。其中每个 URI 都包含有关该服务如何对其进行分析的说明。

仅从数据源的所有 Orders 中返回 ID 属性等于 201 的 Orders

http://host/service.svc/Orders?$filter=ID%20eq%201

匹配 fullname 属性值等于“Jones, David”的所有 Customers

http://host/service.svc/Customers?$filter=
         'Jones, David' eq insert(fullname, length(lastname), ',')

将算术表达式分析为 1 + (2 * 3),而不是 (1 + 2) * 3。由于筛选表达式只是一个始终计算为 true 的测试用例,因此 URI 表示针对所有 OrderLines 的请求。

http://host/service.svc/OrderLines?$filter=1 add 2 mul 3 lt 10

抽象语法

以下规则显示在已扩充的巴科斯-诺尔范式规范中定义的、用于构造 ADO.NET 数据服务 URI 的语法元素。该规范在 RFC 4234 中进行了定义。ADO.NET 数据服务 URI 由以下三个部分组成:服务根、资源路径和查询选项。将这三部分组合在一起可构成用于对 ADO.NET 数据服务中的任何资源进行寻址的 URI。

ADO.NET_DS_URI   = "http://" serviceRoot [ resourcePath ["?" queryOptions ] ] 

ServiceRoot      = host [ ":" port ] [*( "/" segment-nz )]

ResourcePath     = "/" EntitySet | serviceOperation [ navPath ]  

navPath          = ("("keyPredicate")" [ navPath_np / propertyPath / propertyPath_ct ] )

navPath_np       = "/" ("$links" / NavigationProperty) /
                     (NavigationProperty [ navPath ])

EntityPropertyPath     = "/" EntityProperty [ "/$value" ] 

ComplexTypePropertyPath_ct  = 1*("/" ComplexType) [ propertyPath ] 
  
keyPredicate     = keyPredicate_single | keyPredicate_cmplx

keyPredicate_single  = 1*DIGIT | ("’" 1*unreserved "’") | 1*(HEXDIGHEXDIG)) | 
                       keyPredicate_complex
                       //NOTE: strings, GUIDs and dates are quoted

keyPredicate_cmplx   = resourceProp "=" keyPredicate [“,” keyPredicate_cmplx]

queryOptions     = sysQueryOperation / serviceOpParamName 
                     *("&" sysQueryOperation / serviceOpParam)

DIGIT            = as defined in RFC 3986 (0-9)
Host             = as defined in RFC 3986
Port             = as defined in RFC 3986
segment-nz       = as defined in RFC 3986 (A non empty sequence of chars outside set of URI reserved characters.)
pchar            = as defined in RFC 3986 (A non empty sequence of chars outside set of URI reserved characters.)

serviceOperation = the name of a service operation. 

EntitySet      = the name of an EntitySet. Allowed characters match the set of allowed characters for EntitySet names in the EDM specification.

EntityType = The name of an EntityType within the EntitySet referenced in the prior path segment. Allowed characters match the set of allowed characters for EntityType names in the EDM specification.

Property     = The name of a property on the entity type or complex type in the prior path segment or current path segment if filtering by key. Allowed characters match the set of allowed characters for EntityType property names in the EDM specification.  

NavigationProperty = the name of a NavigationProperty or Navigation Link on the EntityType in the prior path segment. If the prior segment is an EntitySet,this property must be on the type within the given set. Allowed characters match the set of allowed characters for NavigationProperty names in the EDM specification.

systemQueryOperation = "$" query "=" query 

serviceOperationParam    = query "=" query  

有关 URI 语法的更多信息和示例,请参见资源路径规则和语义(ADO.NET 数据服务框架)

另请参见

概念

资源路径规则和语义(ADO.NET 数据服务框架)
ADO.NET 数据服务查询选项
ADO.NET 数据服务系统查询选项