2003年度 データベース論
Download
Report
Transcript 2003年度 データベース論
WSDL
ソフトウェア特論
第9回 / 2004-07-09
お知らせ
レポート課題を出しています。
提出は 7/30 (金) まで。
今後の講義予定
7/9 (金) きょう
7/20 (火) 2限
きょうの目標
WSDL の概要を知る。
次の2つの関係について理解する。
WSDL
JWSDP によって生成されたスタブ
WSDLの概要
WSDL (1)
Webサービスの具体的な内容を書いてあ
るもの
どこにアクセスすればよいのか
どのようなメソッドがあるか
など
(Javaでの)インタフェースのようなもの
XML で記述されている。
WSDL (2)
WSDL から、Webサービスにアクセスする
クライアントプログラムを生成できる。
JWSDP (JavaのWebサービス開発キット)では
wscompile というツールで WSDL から Javaプ
ログラムを生成
クライアントプログラムからはメソッドを呼び出
すだけで、プログラムの中身はWebサービス
側にあるので、これでうまくいく。
WSDL (3)
既存のプログラムからWSDLを生成するこ
ともできる。
Google Web APIs では、WSDL文書がは
じめから付属している。
WSDL = Web Services Description
Language = Webサービス記述言語
WSDLの構造
全体的な構造
<definitions>
<types>
<message>
<portType>
<binding>
<service>
</definitions>
…… </types>
…… </message>
…… </portType>
…… </binding>
…… </service>
WSDLの読みかた
service 要素から types 要素に向かって、下から
順に読むとわかりやすい。
<definitions>
<types>
…… </types>
<message>
…… </message>
<portType>
…… </portType>
<binding>
…… </binding>
<service>
…… </service>
</definitions>
service 要素 (1)
<service name="GoogleSearchService">
<port name="GoogleSearchPort"
binding="typens:GoogleSearchBinding">
<soap:address location=
"http://api.google.com/search/beta2"/>
</port>
</service>
service 要素 (2)
GoogleSearchService というサービス名に
なる。
service要素では、主にエンドポイントを指
定する。
エンドポイント = Webサービスを提供して
いるURL
service 要素 (3)
<soap:address location=
"http://api.google.com/search/beta2"/>
この Web サービスは、
http://api.google.com/search/beta2 とい
うURLにアクセスする。
service 要素 (4)
<port name="GoogleSearchPort"
binding="typens:GoogleSearchBinding">
……
</port>
binding 要素の name 属性である
GoogleSearchBinding が登場している。
binding 要素 (1)
<binding name="GoogleSearchBinding"
type="typens:GoogleSearchPort">
……
</binding>
GoogleSearchBinding という名前を持つ
portType 要素の name 属性である
“GoogleSearchPort” が登場
binding 要素 (2)
<binding name="GoogleSearchBinding"
type="typens:GoogleSearchPort">
<soap:binding style="rpc“ transport=
"http://schemas.xmlsoap.org/soap/http"/>
<operation>
……
</operation>
</binding>
binding 要素 (3)
<soap:binding style="rpc“ transport=
"http://schemas.xmlsoap.org/soap/http"/>
rpc = 通信の手法を指定する。rpc かdocument
となる。
http://schemas.xmlsoap.org/soap/http = トラ
ンスポート層のプロトコルとして HTTP を利用す
る。
binding 要素 (4)
operation 要素は、このWebサービスで利用でき
る操作 (メソッドに対応)
input 要素はメソッドの引数に対応
output 要素はメソッドの返値に対応
<operation name="doGoogleSearch">
<input>
……
</input>
<output>
......
</output>
</operation>
binding 要素 (5)
<operation name="doGoogleSearch">
<input>
<soap:body use="encoded"
namespace="urn:GoogleSearch“
encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output> ...... </output>
</operation>
binding 要素 (6)
input (引数) と output (返値) のいずれも、
SOAPでデータが渡されるときに 「SOAPエ
ンコーディング」という手法が使われる。
ただし、現在ではあまり推奨されない手法
となっている。
binding 要素 (7)
binding 要素では、主に Webサービスの
通信の方法について定める。
トランスポート層として HTTP を使う
SOAP を利用する
SOAPエンコーディングを利用する
……
portType 要素 (1)
<portType name="GoogleSearchPort">
......
<operation name="doGoogleSearch">
<input message=
"typens:doGoogleSearch"/>
<output message=
"typens:doGoogleSearchResponse"/>
</operation>
</portType>
portType 要素 (2)
GoogleSearchPort という名前を持つ。
(binding要素で出てきた) operation 要素
がある。
portType 要素 (3)
operation 要素の input, output 要素では、
引数や返値の型を指定する。
ここでは抽象的な名前だけで、型の具体的な
内容は message 要素で指定する。
<operation name="doGoogleSearch">
<input message=
"typens:doGoogleSearch"/>
<output message=
"typens:doGoogleSearchResponse"/>
</operation>
portType 要素 (4)
portType 要素は、Javaのインタフェースに
相当する。
メソッドの名前、引数や返値の型など
message 要素 (1)
<message name="doGoogleSearch">
<part name="key“ type="xsd:string"/>
<part name="q“
type="xsd:string"/>
<part name="start“ type="xsd:int"/>
......
</message>
<message name="doGoogleSearchResponse">
<part name=“return”
type="typens:GoogleSearchResult"/>
</message>
message 要素 (2)
portType 要素の input・output 要素で使
われる型を指定する。
“doGoogleSearch” という message には
string 型の key
string 型の q
int 型の start
などが含まれる
message 要素 (3)
こうした key, q, start といったものは、
portType 要素の中で定義されている
doGoogleSearch オペレーションの引
数に対応する。
message 要素 (4)
Part要素での型の指定は、XML Schema
の型を使う。
xsd:string など
<message name="doGoogleSearch">
<part name="key“ type="xsd:string"/>
<part name="q“ type="xsd:string"/>
<part name="start“ type="xsd:int"/>
......
</message>
message 要素 (5)
組み込みのデータ型で対応できないときは、
後述する types 要素で新しい型を作成す
る。
<message
name="doGoogleSearchResponse">
<part name="return"
type="typens:GoogleSearchResult"/>
</message>
types 要素 (1)
<types>
<xsd:schema xmlns=
"http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:GoogleSearch">
<xsd:complexType
name="GoogleSearchResult">
……
</xsd:complexType>
......
</types>
types 要素 (2)
<xsd:complexType name="GoogleSearchResult">
<xsd:all>
<xsd:element name="documentFiltering"
type="xsd:boolean"/>
<xsd:element name="resultElements"
type="typens:ResultElementArray"/>
......
</xsd:all>
</xsd:complexType>
types 要素 (3)
XML Schema を使って、
GoogleSearchResult という新しい型を生
成する。
それぞれの要素の型を、さらに XML
Schema で宣言することもできる。
WSDLの各要素の概要
service要素では、主にエンドポイントを指定する。
binding 要素では、主に Webサービスの通信の
方法について定める。
portType 要素は、Javaのインタフェースに相当
する。
Message要素では、portType 要素の input・
output 要素で使われる型を指定する。
types 要素では、XML Schema を使って、 新し
い型を定義する。