REST データ・サービスでの非エンティティーの取得

REST データ・サービスでは、エンティティー・コレクションやプロパティーなど、エンティティー以外のものも取得できます。

エンティティー・コレクションの取得

RetrieveEntitySet 要求を使用して、クライアントで eXtreme Scale エンティティーのセットを取得できます。エンティティーは、応答ペイロードで、Atom Feed Document または JSON 配列として表されます。 WCF Data Services で定義されている RetrieveEntitySet プロトコルの詳細については、MSDN: RetrieveEntitySet Request を参照してください。

以下の RetrieveEntitySet 要求の例では、Customer('IBM') エンティティーに関連付けられたすべての Order エンティティーを取得します。 この例では、5000 および 5001 の Order のみが表示されます。

AtomPub

  • メソッド: GET
  • 要求 URI: http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Customer('IBM')/orders
  • 要求ヘッダー: Accept: application/atom+xml
  • 要求ペイロード: なし
  • 応答ヘッダー: Content-Type: application/atom+xml
  • 応答ペイロード:
    <?xml version="1.0" encoding="utf-8"?>
    <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">Order</title>
        <id>http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/
    					Order</id>
        <updated>2009-12-16T22:53:09.062Z</updated>
        <link rel = "self" title = "Order" href = "Order"/>
        <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:53:09.062Z</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:53:09.062Z</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>
  • 応答コード: 200 OK

JSON

  • メソッド: GET
  • 要求 URI: http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Customer('IBM')/orders
  • 要求ヘッダー: Accept: application/json
  • 要求ペイロード: なし
  • 応答ヘッダー: Content-Type: application/json
  • 応答ペイロード:
    {"d":[{"__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"}}}]}
  • 応答コード: 200 OK

プロパティーの取得

RetrievePrimitiveProperty 要求を使用して、eXtreme Scale エンティティー・インスタンスのプロパティーの値を取得できます。応答ペイロードで、プロパティーの値は、AtomPub 要求の場合は XML フォーマットとして、JSON 要求の場合は JSON オブジェクトとして表されます。 RetrievePrimitiveProperty 要求の詳細については、MSDN: RetrievePrimitiveProperty Request を参照してください。

以下の RetrievePrimitiveProperty 要求の例では、Customer('IBM') エンティティーの contactName プロパティーを取得します。

AtomPub

  • メソッド: GET
  • 要求 URI: http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Customer('IBM')/contactName
  • 要求ヘッダー: Accept: application/xml
  • 要求ペイロード: なし
  • 応答ヘッダー: Content-Type: application/atom+xml
  • 応答ペイロード:
    <contactName xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
        John Doe
    </contactName>
  • 応答コード: 200 OK

JSON

  • メソッド: GET
  • 要求 URI: http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Customer('IBM')/contactName
  • 要求ヘッダー: Accept: application/json
  • 要求ペイロード: なし
  • 応答ヘッダー: Content-Type: application/json
  • 応答ペイロード: {"d":{"contactName":"John Doe"}}
  • 応答コード: 200 OK

プロパティーの値の取得

RetrieveValue 要求を使用して、eXtreme Scale エンティティー・インスタンスのプロパティーの未加工値を取得できます。応答ペイロードで、プロパティーの値は、未加工値として表されます。 エンティティー型が以下のいずれかの場合、応答のメディア・タイプは「text/plain」です。それ以外の場合は、応答のメディア・タイプは「application/octet-stream」です。以下に型をリストします。
  • Java プリミティブ型およびそれぞれのラッパー
  • java.lang.String
  • byte[]
  • Byte[]
  • char[]
  • Character[]
  • enums
  • java.math.BigInteger
  • java.math.BigDecimal
  • java.util.Date
  • java.util.Calendar
  • java.sql.Date
  • java.sql.Time
  • java.sql.Timestamp

RetrieveValue 要求の詳細については、MSDN: RetrieveValue Request を参照してください。

以下の RetrieveValue 要求の例では、Customer('IBM') エンティティーの contactName プロパティーの未加工値を取得します。

  • 要求メソッド: GET
  • 要求 URI: http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Customer('IBM')/contactName/$value
  • 要求ヘッダー: Accept: text/plain
  • 要求ペイロード: なし
  • 応答ヘッダー: Content-Type: text/plain
  • 応答ペイロード: John Doe
  • 応答コード: 200 OK

リンクの取得

RetrieveLink 要求を使用して、対 1 アソシエーションまたは対多アソシエーションを表すリンクを取得できます。 対 1 アソシエーションの場合、リンクはある eXtreme Scale エンティティー・インスタンスから別のエンティティー・インスタンスに張られ、そのリンクは応答ペイロードで表されます。対多アソシエーションの場合、リンクはある eXtreme Scale エンティティー・インスタンスから、指定した eXtreme Scale エンティティー・コレクション内の他のすべてのエンティティー・インスタンスに張られ、応答は応答ペイロードでリンクのセットとして表されます。RetrieveLink 要求の詳細については、MSDN: RetrieveLink Request を参照してください。

以下に、RetrieveLink 要求の例を示します。 この例では、エンティティー Order(orderId=5000,customer_customerId='IBM') とその Customer 間のアソシエーションを取得します。 応答では、Customer エンティティー URI が示されます。

AtomPub

  • メソッド: GET
  • 要求 URI: http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Order(orderId=5000,customer_customerId='IBM')/$links/customer
  • 要求ヘッダー: Accept: application/xml
  • 要求ペイロード: なし
  • 応答ヘッダー: Content-Type: application/xml
  • 応答ペイロード:
    <?xml version="1.0" encoding="utf-8"?>
    <uri>http://localhost:8080/wxsrestservice/restservice/
    			NorthwindGrid/Customer('IBM')</uri>
  • 応答コード: 200 OK

JSON

  • メソッド: GET
  • 要求 URI: http://localhost:8080/wxsrestservice/restservice/NorthwindGrid/Order(orderId=5000,customer_customerId='IBM')/$links/customer
  • 要求ヘッダー: Accept: application/json
  • 要求ペイロード: なし
  • 応答ヘッダー: Content-Type: application/json
  • 応答ペイロード: {"d":{"uri":"http:¥/¥/localhost:8080¥/wxsrestservice¥/restservice¥/NorthwindGrid¥/Customer('IBM')"}}

サービス・メタデータの取得

RetrieveServiceMetadata 要求を使用して、概念スキーマ定義言語 (CSDL) 文書を取得できます。この文書には、eXtreme Scale REST データ・サービスに関連したデータ・モデルが記述されています。RetrieveServiceMetadata 要求の詳細については、MSDN: RetrieveServiceMetadata Request を参照してください。

サービス文書の取得

RetrieveServiceDocument 要求を使用して、eXtreme Scale REST データ・サービスによって公開されたリソースのコレクションが記述されたサービス文書を取得できます。RetrieveServiceDocument 要求の詳細については、MSDN: RetrieveServiceDocument Request を参照してください。