CData Virtuality はWeb サービスとの通信を容易にします。RESTful とSOAP の両方のWeb サービスを使用できます。必要なものはただ一つ、Webサービスというタイプの有効なデータソースです。Web サービスデータソースは、以下に説明するように、Web サービスからデータを取得するための2つのストアドプロシージャを提供します。
Web UI で Web サービス・データ・ソースを追加するには、Sourcesタブを開き、+ New Sourceをクリックし、REST/SOAP Web Servicesボタンをクリックします(または、これらの用語を検索します):
ウィザードは次のようになります:
必須情報はデータ・ソースのエイリアスのみです。上記の例では、restapi。エンドポイント、つまりウェブアドレスを指定することができ、後でリクエストに暗黙的に使うことができます。このフィールドは空にすることができ、プロシージャを使用する際には常にエンドポイントを指定する必要があります。このフィールドを空白にすると、異なるAPIへのあらゆる種類のWebサービスリクエストに1つのデータソースを使用できます。もちろん、複数のデータソースを作成し、異なるAPIに割り当てて論理的に使用することも可能です。
また、セキュリティの種類を指定することも可能です。セキュリティの種類(および提供しなければならない追加情報)を選択した場合、この情報は常に各Web リクエストで送信されることに注意してください。しかし、例えばAPIがOAuth2を厳密に要求している場合などは、OAuth2の設定が必要になるかもしれません。
データ・ソースが追加されると、以下の2つのプロシージャがあります:
- invoke(): SOAPリクエストに使用 (ここでは ws.invoke )
- invokeHTTP(): REST リクエストに使用 (ここでは ws.invokeHTTP )
REST Web Services (invokeHttp() Procedure)
以下は入力パラメータとその使用方法です:
Parameter | Description |
---|---|
| The request action, usually one of the following: |
| The data of the object which is sent to the API; null if data shall only be retrieved from the API |
| The web endpoint to where the request is sent; can be a full URL or only a suffix (it is appended to the data source's default endpoint). If null, the web service's default endpoint is used |
| The data type of the object which is sent to the API; null if data shall only be retrieved from the API. Valid values are |
| Additional headers that are sent to the API, such as authorization headers |
| Enables you to ignore HTTP errors |
Sample Call
invokeHTTP()
手順を使用したこの単純な REST リクエストには、アクションとエンドポイントのみが含まれます:
SELECT
TO_chars(w.result,
'UTF-8'
)
FROM
(
CALL generic_ws.invokeHTTP (
action
=>
'GET'
,
endpoint =>
'https://academy.datavirtuality.com/wp-content/uploads/2022/06/forecast.json'
)
)w;;
ウェブサービスを呼び出した結果は、例えばTEXTTABLE
、XMLTABLE
、JSONTOXML
関数を使用してさらに処理することができます。この処理は、CData Virtuality Studio のXML/JSON またはCSV ウィザードを使用して定義できます。
パラメータを渡す場合は、QueryString
関数を使用して URL を作成します。以下の例では、以下のURLを構築します:https://www.7timer.info/bin/astro.php?lon=113.2&lat=23.1&ac=0&unit=metric&output=json&tzshift=0 :
SELECT
TO_chars(w.result,
'UTF-8'
)
FROM
(
CALL generic_ws.invokeHTTP (
action
=>
'GET'
,
endpoint => QueryString(
'https://www.7timer.info/bin/astro.php'
,
113.2
AS
lon,
23.1
AS
lat,
0
AS
ac,
'metric'
AS
unit,
'json'
AS
"output"
,
0
AS
tzshift
)
)
)w;;
SOAP Web Services (invoke() Procedure)
以下は入力パラメータとその使用方法です:
Parameter | Description |
---|---|
| The request action; usually GET or POST |
| The web service binding, can be one of the following: HTTP, SOAP11, SOAP12 |
| The actual XML request according to SOAP standards |
| The web endpoint to where the request is sent; can be a full URL or only a suffix (it is appended to the data source's default endpoint). If null, the web service's default endpoint is used |
与えられたSOAPウェブサービスのサンプルリクエストを取得する簡単な方法は、有効なWSDLの場所(ローカルまたはウェブ)を必要とするだけで、リクエストテンプレートを生成できるツールSoapUIを使用することです。のWSDL Schemaファイルが良いサンプルです。 https://schemas.xmlsoap.org/wsdl/soap/
Sample Call
invoke()
プロシージャを使用した以下のSOAP リクエストは、ドイツの首都を要求するSOAP 呼び出しを作成します。バインディングとして HTTP を使用し、アクションとしてPOST
を使用し、SoapUI によって生成された XML リクエストを使用します。そうでない場合は、手動でWSDLファイルをブラウズし、そこから得られる情報を使ってXMLを構築しなければなりません:
SELECT
"w.result"
FROM
(
EXEC
"generic_ws"
.invoke(
"binding"
=>
'HTTP'
,
"action"
=>
'POST'
,
"request"
=>
'<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CapitalCity xmlns="http://www.oorsprong.org/websamples.countryinfo">
<sCountryISOCode>DE</sCountryISOCode>
</CapitalCity>
</soap:Body>
</soap:Envelope>
'
,
"endpoint"
=>
'http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso'
)
)
AS
w;;
Sample Result
<
soap
:Envelope
xmlns:soap
=
"http://schemas.xmlsoap.org/soap/envelope/"
>
<
soap
:Body>
<
m
:CapitalCityResponse
xmlns:m
=
"http://www.oorsprong.org/websamples.countryinfo"
>
<
m
:CapitalCityResult>Berlin</
m
:CapitalCityResult>
</
m
:CapitalCityResponse>
</
soap
:Body>
</
soap
:Envelope>
See Also
Facebook: Handle Paged Results ページングされた結果を操作する方法については、こちらをご覧ください。