Um Pedido RetrieveEntity é usado por um cliente para recuperar uma entidade do eXtreme Scale. A carga útil da resposta contém os dados da entidade no formato AtomPub ou JSON. Além disso, o operador do sistema $expand pode ser utilizado para expandir as relações. As relações são representadas em sequência dentro da resposta do serviço de dados como um Atom Feed Document, que é uma relação para-muitos, ou um Atom Entry Document que é uma relação para-um.
O exemplo de RetrieveEntity a seguir recupera uma entidade Customer com uma chave.
AtomPubGET
http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Customer('ACME')
Aceitar: application/atom+xml
Nenhum
Tipo de Conteúdo: 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')
Aceitar: application/json
Nenhum
Tipo de Conteúdo: 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
Uma consulta também pode ser utilizada com um pedido RetrieveEntitySet ou RetrieveEntity. Uma consulta é especificada pelo operador $filter do sistema.
Para obter detalhes sobre o operador $filter, consulte: MSDN: Opção de Consulta do Sistema de Filtros ($filter)
O protocolo OData suporta várias expressões comuns. O serviço de dados REST do eXtreme Scale suporta um subconjunto de expressões definidas na especificação:
As expressões a seguir não estão disponíveis:
Para obter uma lista e uma descrição completas das expressões que estão disponíveis no Microsoft WCF Data Services, consulte a seção 2.2.3.6.1.1: Sintaxe de Expressão Comum.
O exemplo a seguir demonstra um pedido RetrieveEntity com uma consulta. Neste exemplo, todos os clientes cujo nome do contato é “RoadRunner” são recuperados. O único cliente que corresponde a esse filtro é Customer('ACME'), conforme mostrado na carga útil da resposta.
<?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"}}}]}
O operador do sistema $expand pode ser utilizado para expandir associações. As associações são representadas em linha na resposta do serviço de dados. As associações com diversos valores (para-muitos) são representadas como um Atom Feed Document ou matriz JSON. As associações com valor único (para-um) são representadas como um Atom Entry Document ou objeto JSON.
Para obter mais detalhes sobre o operador do sistema $expand, consulte Expandir Opção de Consulta do Sistema ($expand).
Veja aqui um exemplo de uso do operador do sistema $expand. Neste exemplo, recuperamos a entidade Customer('IBM') com Orders 5000, 5001 e outras associadas a ela. A cláusula $expand está configurada como “orders”, portanto, a coleta de pedidos será expandida como sequencial na carga útil da resposta. Apenas os pedidos 5000 e 5001 são exibidos aqui.
<?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"}}}]}}