Une demande trieveEntity est utilisée par un client pour extraire une entité eXtreme Scale. La charge de la réponse contient les données d'entité au format AtomPub ou JSON. En outre, l'opérateur système $expand permet de développer les relations. Les relations sont représentées en ligne dans la réponse du service de données sous la forme d'un document de flux Atom, qui est une relation to-many, ou un document Atom Entry qui est une relation to-one.
L'exemple RetrieveEntity ci-après extrait une entité Customer avec sa clé.
AtomPubGET
http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Customer('ACME')
Accept: application/atom+xml
Aucun
Content-Type: application/atom+xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<entry xml:base = "http://localhost:8080/wxsrestservice/
restservice" xmlns:d= "http://schemas.microsoft.com/ado/2007/
08/dataservices" xmlns:m = "http://schemas.microsoft.com/ado/2007/
08/dataservices/metadata" xmlns = "http://www.w3.org/2005/Atom">
<category term = "NorthwindGridModel.Customer" scheme = "http://
schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<id>http://localhost:8080/wxsrestservice/restservice/
NorthwindGrid/Customer('ACME')</id>
<title type = "text"/>
<updated>2009-12-16T19:52:10.593Z</updated>
<author>
<name/>
</author>
<link rel = "edit" title = "Customer" href = "Customer(
'ACME')"/>
<link rel = "http://schemas.microsoft.com/ado/2007/08/
dataservices/related/
orders" type = "application/atom+xml;type=feed" title =
"orders" href ="Customer('ACME')/orders"/>
<content type = "application/xml">
<m:properties>
<d:customerId>ACME</d:customerId>
<d:city m:null = "true"/>
<d:companyName>RoaderRunner</d:companyName>
<d:contactName>ACME</d:contactName>
<d:country m:null = "true"/>
<d:version m:type = "Edm.Int32">3</d:version>
</m:properties>
</content>
</entry>
200 OK
GET
http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Customer('ACME')
Accept: application/json
Aucun
Content-Type: application/json
{"d":{"__metadata":{"uri":"http://localhost:8080/wxsrestservice/
restservice/NorthwindGrid/Customer('ACME')",
"type":"NorthwindGridModel.Customer"},
"customerId":"ACME",
"city":null,
"companyName":"RoaderRunner",
"contactName":"ACME",
"country":null,
"version":3,
"orders":{"__deferred":{"uri":"http://localhost:8080/
wxsrestservice/restservice/
NorthwindGrid/Customer('ACME')/orders"}}}}
200 OK
Une requête peut également être utilisée avec une demande RetrieveEntitySet ou RetrieveEntity. Une requête est spécifiée par l'opérateur système $filter.
Pour des explications détaillées de l'opérateur $filter, voir MSDN: Filter System Query Option ($filter).
Le protocole OData prend en charge plusieurs expressions communes. Le service de données REST eXtreme Scale prend en charge un sous-ensemble des expressions définies dans la spécification :
Les expressions suivantes ne sont pas disponibles :
Pour obtenir la liste complète et la description des expressions qui sont disponibles dans Microsoft WCF Data Services, voir la section 2.2.3.6.1.1 : Synaxe des expressions communes.
L'exemple suivant illustre une demande RetrieveEntity avec une requête. Dans cet exemple, tous les clients dont le nom de contact est “RoadRunner” sont extraits. Le seul client qui correspond à ce filtre est Customer('ACME'), comme indiqué dans la charge de la réponse.
<?xml version="1.0" encoding="iso-8859-1"?>
<feed
xml:base="http://localhost:8080/wxsrestservice/restservice"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/
dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/
dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<title type="text">Customer</title>
<id>http://localhost:8080/wxsrestservice/restservice/
NorthwindGrid/Customer </id>
<updated>2009-09-16T04:59:28.656Z</updated>
<link rel="self" title="Customer" href="Customer" />
<entry>
<category term="NorthwindGridModel.Customer"
scheme="http://schemas.microsoft.com/ado/2007/08/
dataservices/scheme" />
<id>
http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/
Customer('ACME')</id>
<title type="text" />
<updated>2009-09-16T04:59:28.656Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Customer" href="Customer('ACME')" />
<link
rel="http://schemas.microsoft.com/ado/2007/08/dataservices/
related/orders"
type="application/atom+xml;type=feed" title="orders"
href="Customer('ACME')/orders" />
<content type="application/xml">
<m:properties>
<d:customerId>ACME</d:customerId>
<d:city m:null = "true"/>
<d:companyName>RoaderRunner</d:companyName>
<d:contactName>ACME</d:contactName>
<d:country m:null = "true"/>
<d:version m:type = "Edm.Int32">3</d:version>
</m:properties>
</content>
</entry>
</feed>
http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Customer?$filter=contactName eq 'RoadRunner'
{"d":[{"__metadata":{"uri":"http://localhost:8080/wxsrestservice/
restservice/NorthwindGrid/Customer('ACME')",
"type":"NorthwindGridModel.Customer"},
"customerId":"ACME",
"city":null,
"companyName":"RoaderRunner",
"contactName":"ACME",
"country":null,
"version":3,
"orders":{"__deferred":{"uri":"http://localhost:8080/
wxsrestservice/restservice/NorthwindGrid/
Customer('ACME')/orders"}}}]}
L'opérateur système $expand permet de développer des associations. Les associations sont représentées en ligne dans la réponse du service de données. Les associations à plusieurs valeurs (to-many) sont représentées comme document de flux Atom ou tableau JSON. Les associations à valeur unique (to-one) sont représentées comme document d'entrée Atom ou objet JSON.
Pour plus de détails sur l'opérateur $expand, voir Expand System Query Option ($expand).
Voici un exemple d'utilisation de l'opérateur système $expand. Dans cet exemple, nous extrayons l'entité Customer('IBM') associée entre autres aux commandes 5000 et 5001. La clause $expand reçoit la valeur “orders”, de sorte que la collection de commandes soit étendue comme en ligne dans la charge de la réponse. Seules les commandes 5000 et 5001 sont affichées ici.
<?xml version="1.0" encoding="utf-8"?>
<entry xml:base = "http://localhost:8080/wxsrestservice/restservice"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m = "http://schemas.microsoft.com/ado/2007/08/dataservices/
metadata" xmlns = "http://www.w3.org/2005/Atom">
<category term = "NorthwindGridModel.Customer" scheme = "http://schemas.
microsoft.com/ado/2007/08/dataservices/scheme"/>
<id>http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/
Customer('IBM')</id>
<title type = "text"/>
<updated>2009-12-16T22:50:18.156Z</updated>
<author>
<name/>
</author><link rel = "edit" title = "Customer" href =
"Customer('IBM')"/>
<link rel = "http://schemas.microsoft.com/ado/2007/08/dataservices/
related/orders" type = "application/atom+xml;type=feed" title =
"orders" href = "Customer('IBM')/orders">
<m:inline>
<feed>
<title type = "text">orders</title>
<id>http://localhost:8080/wxsrestservice/restservice/
NorthwindGrid/Customer('IBM')/orders</id>
<updated>2009-12-16T22:50:18.156Z</updated>
<link rel = "self" title = "orders" href = "Customer
('IBM')/orders"/>
<entry>
<category term = "NorthwindGridModel.Order" scheme =
"http://schemas.microsoft.com/ado/2007/08/
dataservices/scheme"/>
<id>http://localhost:8080/wxsrestservice/restservice/
NorthwindGrid/Order(orderId=5000,customer_customerId=
'IBM')</id>
<title type = "text"/>
<updated>2009-12-16T22:50:18.156Z</updated>
<author>
<name/>
</author>
<link rel = "edit" title = "Order" href =
"Order(orderId=5000,customer_customerId='IBM')"/>
<link rel = "http://schemas.microsoft.com/ado/2007/08/
dataservices/related/customer" type = "application/
atom+xml;type=entry" title ="customer" href =
"Order(orderId=5000,customer_customerId='IBM')/customer"/>
<link rel = "http://schemas.microsoft.com/ado/2007/08/
dataservices/related/orderDetails" type = "application/
atom+xml;type=feed" title ="orderDetails" href =
"Order(orderId=5000,customer_customerId='IBM')/orderDetails"/>
<content type = "application/xml">
<m:properties>
<d:orderId m:type = "Edm.Int32">5000</d:orderId>
<d:customer_customerId>IBM</d:customer_customerId>
<d:orderDate m:type = "Edm.DateTime">
2009-12-16T19:46:29.562</d:orderDate>
<d:shipCity>Rochester</d:shipCity>
<d:shipCountry m:null = "true"/>
<d:version m:type = "Edm.Int32">0</d:version>
</m:properties>
</content>
</entry>
<entry>
<category term = "NorthwindGridModel.Order" scheme =
"http://schemas.microsoft.com/ado/2007/08/
dataservices/scheme"/>
<id>http://localhost:8080/wxsrestservice/restservice/
NorthwindGrid/Order(orderId=5001,customer_customerId=
'IBM')</id>
<title type = "text"/>
<updated>2009-12-16T22:50:18.156Z</updated>
<author>
<name/></author>
<link rel = "edit" title = "Order" href = "Order(
orderId=5001,customer_customerId='IBM')"/>
<link rel = "http://schemas.microsoft.com/ado/2007/
08/dataservices/related/customer" type =
"application/atom+xml;type=entry" title =
"customer" href = "Order(orderId=5001,customer_customerId=
'IBM')/customer"/>
<link rel = "http://schemas.microsoft.com/ado/2007/08/
dataservices/related/orderDetails" type =
"application/atom+xml;type=feed" title =
"orderDetails" href = "Order(orderId=5001,
customer_customerId='IBM')/orderDetails"/>
<content type = "application/xml">
<m:properties>
<d:orderId m:type = "Edm.Int32">5001</d:orderId>
<d:customer_customerId>IBM</d:customer_customerId>
<d:orderDate m:type = "Edm.DateTime">2009-12-16T19:
50:11.125</d:orderDate>
<d:shipCity>Rochester</d:shipCity>
<d:shipCountry m:null = "true"/>
<d:version m:type = "Edm.Int32">0</d:version>
</m:properties>
</content>
</entry>
</feed>
</m:inline>
</link>
<content type = "application/xml">
<m:properties>
<d:customerId>IBM</d:customerId>
<d:city m:null = "true"/>
<d:companyName>IBM Corporation</d:companyName>
<d:contactName>John Doe</d:contactName>
<d:country m:null = "true"/>
<d:version m:type = "Edm.Int32">4</d:version>
</m:properties>
</content>
</entry>
{"d":{"__metadata":{"uri":"http://localhost:8080/wxsrestservice/
restservice/NorthwindGrid/Customer('IBM')",
"type":"NorthwindGridModel.Customer"},
"customerId":"IBM",
"city":null,
"companyName":"IBM Corporation",
"contactName":"John Doe",
"country":null,
"version":4,
"orders":[{"__metadata":{"uri":"http://localhost:8080/
wxsrestservice/restservice/NorthwindGrid/Order(
orderId=5000,customer_customerId='IBM')",
"type":"NorthwindGridModel.Order"},
"orderId":5000,
"customer_customerId":"IBM",
"orderDate":"\/Date(1260992789562)\/",
"shipCity":"Rochester",
"shipCountry":null,
"version":0,
"customer":{"__deferred":{"uri":"http://localhost:8080/
wxsrestservice/restservice/NorthwindGrid/Order(
orderId=5000,customer_customerId='IBM')/customer"}},
"orderDetails":{"__deferred":{"uri":"http://localhost:
8080/wxsrestservice/restservice/NorthwindGrid/
Order(orderId=5000,customer_customerId='IBM')/
orderDetails"}}},
{"__metadata":{"uri":"http://localhost:8080/wxsrestservice/
restservice/NorthwindGrid/Order(orderId=5001,
customer_customerId='IBM')","type":
"NorthwindGridModel.Order"},
"orderId":5001,
"customer_customerId":"IBM",
"orderDate":"\/Date(1260993011125)\/",
"shipCity":"Rochester",
"shipCountry":null,
"version":0,
"customer":{"__deferred":{"uri":"http://localhost:
8080/wxsrestservice/restservice/
NorthwindGrid/Order(orderId=5001,customer_customerId='IBM')/customer"}},
"orderDetails":{"__deferred":{"uri":"http://localhost:8080/
wxsrestservice/restservice/NorthwindGrid/Order(
orderId=5001, customer_customerId='IBM')/
orderDetails"}}}]}}