文書形式と例による解説ガイド
はじめに
WSDLは、あらゆるウェブサービスに関与する方なら十分に馴染みのあるものです。ウェブサービスの説明手段として、SOAPやRESTと共に重要な役割を果たします。
本記事では、実際の文書例を交えながら、WSDLに関する重要な情報を紹介します。ウェブサービスに関わる方は、これから述べる内容にご注目下さい。
WSDLは、対象ウェブサービスが持つ主な機能を説明するための手段です。XMLの構文と書式を利用するインターフェース記述言語です。
この言語は、ウェブサービスの呼び出し方法、必要なパラメータ、返されるデータ構造など、機械でも読み取りやすい形式で説明します。抽象的な要素と具体的な要素の両方について、WSDLは詳しく記述されます。
型シグネチャとの類似点が多いため、同義語とみなされることもあります。
以下に、WSDL (Web Services Description Language) の主要な特徴を示します。
Type- XMLベースのインターフェース記述言語
Existing Version- WSDL 2.0.
Developed by- World Wide Web Consortium
Used Technology- Extensible Markup Language (XML)
Used by- UDDI
WSDLの基本は理解されたようです。では、歴史に少し触れてみましょう!
WSDLは2000年に、Ariba、IBM、Microsoftという3大IT企業が手を組んだことで誕生しました。既存のSOAPツールキットを分かりやすく説明するために作られ、WSDLの設計には、主要な2種類のサービス記述言語であるSDLとNASSLが組み合わされました。
初版はWSDL 1.0と呼ばれ、いくつかの小さな変更を経て、2001年にWSDL 1.1が標準仕様として採用されました。
2003年になると、W3CにWSDL 1.2が提示され、WSDL 1.2はWSDL 1.1に比べて取り扱いが容易で、開発者にとって自由度が高いと評価されました。
その後2007年に、WSDL 1.2はWSDL 2.0として改訂され、W3C勧告に採用されました。しかし、第三者の多くは最近までWSDL 1.1のサポートに留まっていました。
両バージョンの変更点として、WSDL 2.0ではメッセージの構造がなくなり、ポートはエンドポイント、PortTypesはインターフェースとなり、演算子のオーバーロードはサポートされなくなりました。また、記述言語には幅広い意味付けが取り入れられています。
一般的なWSDL文書は、対象ウェブサービスを定義するために使用されます。そのため、各要素を十分に理解することが重要です。
WSDLファイルには、ウェブサービスの配置場所やそれに付随する処理の情報が含まれ、SOAPメッセージの送受信に関する詳細も記載されています。
一見すると、様々なウェブサービス関連情報が記述されているため、WSDL文書は複雑で分かりにくく見えるかもしれません。しかし、その情報は後に他のクライアントアプリでも利用されます。
つまり、WSDLは実際のはがきのようなもので、ウェブサービスの住所と、クライアントの要求に応じた主要な機能が記されています。
Structure:
<wsdl:definitions ...>
<wsdl:types>
...
</wsdl:types>
types 2
...
<wsdl:message ...>
...
</wsdl:message>
message 2
...
<wsdl:portType ...>
<wsdl:operation ...>
input
output
</wsdl:operation>
</wsdl:portType>
<wsdl:binding ...>
operation 1
operation 2
...
</wsdl:binding>
<wsdl:service ...>
port 1
port 2
...
</wsdl:service>
</wsdl:definitions>
WSDL文書は、ウェブサービスの重要な情報を説明するために、様々な要素を必要とします。これらは以下のとおりです:
Element #1 - Definitions
ウェブサービスの名称を保持し、WSDLの中で最も重要な部分といえます。文書の最上部に位置し、各サービス要素の名前空間を定義します。
文書の根幹として、サービス記述の終わりで閉じられます。
多くのパーサは、schema、soap、wsdlといった名前空間をデフォルトで認識しますが、その他は定義が必要です。
構文は次のとおりです:
wsdl:definitions
<wsdl:definitions name="name_to_be_specified"
targetNamespace="target_uri"
xmlns:tns="target_uri"
xmlns:wsdl="wsdl_uri"
xmlns:xxxx="respective_uri" ...>
...
</wsdl:definitions>
ここで、ターゲット名前空間のURIは接頭辞を付与するURIと同一である必要があります。
変数 'name' にはWSDL文書の名称が格納されます。
xmlns:wsdlは基本のWSDL要素用の名前空間接頭辞を付与するため、xmlns:xxxxは他言語からインポートされたWSDL拡張要素用の接頭辞を割り当てるために使用されます。
Example:
<wsdl:definitions name="rootEXAMPLE"
targetNamespace="http://www.example.com/wsdl_example_service/"
xmlns:tns="http://www.example.com/wsdl_example_service/"
xmlns:wsdl="http://www.example.com/wsdl"
xmlns:soap="http://www.example.com/soap" ...>
...
</wsdl:definitions>
Element #2 - Data Types
メッセージでやり取りされるデータの種類を説明します。クライアント側でのデータ型の正確な取り扱いに欠かせず、ウェブサービスの適切な処理にも役立ちます。
Syntax:
<wsdl:types>
... plug elements from different languages that you’d imported for extensibility...
</wsdl:types>
Example: EntReqとExitResのデータ型を定義します:
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/wsdl_example_service/">
<xsd:element name="EntReq" type="xsd:string"/>
<xsd:element name="ExitRes" type="xsd:string"/>
</xsd:schema>
</wsdl:types>
Element #3 - Message
メッセージは、情報交換を行うためのものです。WSDLの場合、これは該当ウェブサービスに関するクライアントとサーバの通信となります。
この要素は、入出力操作の主要な詳細を示すために一般的に使用され、引数や文書の形で表すことができます。
Syntax:
<wsdl:message name="messageTKN1">
<wsdl:part name="messageTKN1" element="q1"/>
...
</wsdl:message>
OR
<wsdl:message name="messageTKN1">
<wsdl:part name="messageTKN1" type="q2"/>
...
</wsdl:message>
ここで、メッセージトークンの名前は messageTKN1、参照名は messageTKN2 となります。‘element’または‘type’は、この名前空間におけるメッセージデータ型を示します。
Example:
<wsdl:message name="IP_msg">
<wsdl:part name="IP_part" element="hy:EntReq"/>
</wsdl:message>
Element #4 - Operation
一連のメッセージ操作を含みます。例えば、メッセージキュー、業務プロセス、メッセージの命名規則などがあります。
WSDL文書で利用できる操作の種類は4つあります:
Syntax: 一般的なリクエスト-レスポンス操作の構文は以下のようになります:
<wsdl:operation name="namespace_tkn1" parameterOrder="namespace_tkn">
<wsdl:input name="namespace_tkn2" message="q2"/>
<wsdl:output name="namespace_tkn3" message="q3"/>
...
</wsdl:operation>
Example:
<wsdl:operation name="GetEmpName">
<wsdl:input message="tns:GetEmpNameIP"/>
<wsdl:output message="tns:GetEmpNameOP"/>
</wsdl:operation>
Element #5 - Port type
あらゆる入出力を整理して操作にまとめるための要素です。バインディング操作を説明する明確な操作セットが含まれており、抽象的に使用されるため、様々なトランスポートへの対応が容易です。
Syntax:
<wsdl:portType name="Name_of_the_port_type">
<wsdl:operation name="PT_1">
<wsdl:input name="IP1" message="soap:IP1msg"/>
<wsdl:output name="OP1" message="soap:OP1msg"/>
</wsdl:operation>
<wsdl:operation name="PT_2">
...
</wsdl:operation>
<wsdl:operation name="PT_3">
...
</wsdl:operation>
...
</wsdl:portType>
Example:
<wsdl:portType name="PT_1">
<wsdl:operation name="GetEmpName">
<wsdl:input message="tns:GetEmpNameIP"/>
<wsdl:output message="tns:GetEmpNameOP"/>
</wsdl:operation>
</wsdl:portType>
Element #6 - Binding
Bindingは、特定のPort typeに対して操作やメッセージを定義する際に、基本のプロトコルとデータ形式として用いられます。主にクライアントアプリが該当Port typeを必要とする場合に使用されます。
Syntax:
<wsdl:binding name="EmpSOAPbinding" type="tns:EmpPort">
<soap:binding style="document" transport="soap_uri"/>
<wsdl:operation name="OP1">
<soap:operation soapAction="URI1/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
Example:
<wsdl:binding name="EmpSOAPbinding" type="tns:EmpPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/envelope"/>
<wsdl:operation name="GetEmp">
<soap:operation soapAction="http://example.com/GetEmp"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
Element #7 - Port
Portは、Bindingとネットワークアドレスが組み合わされたもので、サービス通信のアドレスを提供します。
Syntax:
<wsdl:port name="ServicePort" binding="tns:ServiceSoapBinding">
<soap:address location="http://example.com/service_location"/>
</wsdl:port>
Example:
<wsdl:port name="EmpPort" binding="tns:EmpSoapBinding">
<soap:address location="http://example.com/emloyee"/>
</wsdl:port>
Element #8 - Service
Serviceはウェブサービスおよび、そのサービス定義のための全エンドポイントの集合を指します。文書要素や複数のPort要素を含む場合があります。
Syntax:
<wsdl:service name="NamespaceTKN1">
<wsdl:documentation>My first service</wsdl:documentation>
<wsdl:port name="EmpPort" binding="tns:EmpSoapBinding">
<soap:address location="http://example.com/emloyee"/>
</wsdl:port>
</wsdl:service>
Example:
<wsdl:service name="NamespaceEMP1">
<wsdl:documentation>Employee Document</wsdl:documentation>
<wsdl:port name="NamespaceEMP2" binding="q">
... plug imported elements from different languages for extensibility...
</wsdl:port>
</wsdl:service>
上記の主要なWSDL要素に加えて、さらに2つの補助的な要素があります:
<wsdl:definitions name="rootEXAMPLE"
targetNamespace="http://www.example.com/wsdl_example_service/"
xmlns:tns="http://www.example.com/wsdl_example_service/"
xmlns:wsdl="http://www.example.com/wsdl"
xmlns:soap="http://www.example.com/soap" ...>
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/wsdl_example_service/">
<xsd:element name="EntReq" type="xsd:string"/>
<xsd:element name="ExitRes" type="xsd:string"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="messageTKN1">
<wsdl:part name="messageTKN1" type="q2"/>
...
</wsdl:message>
<wsdl:portType name="PT_1">
<wsdl:operation name="GetEmpName">
<wsdl:input message="tns:GetEmpNameIP"/>
<wsdl:output message="tns:GetEmpNameOP"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="EmpSOAPbinding" type="tns:EmpPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/envelope"/>
<wsdl:operation name="GetEmp">
<soap:operation soapAction="http://example.com/GetEmp"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="NamespaceTKN1">
<wsdl:documentation>My first service</wsdl:documentation>
<wsdl:port name="EmpPort" binding="tns:EmpSoapBinding">
<soap:address location="http://example.com/emloyee"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
既にWSDLのBindingには触れており、ウェブサービスがメッセージプロトコルと連携する過程を説明するために使用されることを理解いただいていると思います。一般的には、利用されるメッセージプロトコルはSOAPです。
したがって、SOAP Bindingも知っておくべき用語です。一般的にWSDLのSOAP Bindingは、リモートプロシージャコール (RPC) スタイルに基づくBindingです。場合によっては、documentスタイルのBindingとなることもあります。エンコード方式またはリテラル方式が使用されます。
WSDL 1.1を利用する場合、SOAP 1.1を処理するための内蔵拡張機能により、SOAPの詳細をこれまで以上に分かりやすく説明できます。その拡張機能で容易に説明できるSOAPの主要な要素には、SOAPエンコーディングスタイル、SOAPヘッダー、SOAPAction HTTPヘッダーがあります。
主要なSOAP Binding拡張要素は以下の通りです:
soap: binding
この要素を使用することで、SOAP経由でのBindingが可能であることが示されます。style属性はSOAPメッセージの形式を示し、rpcという値はRPC形式を表します。the transport属性からは、SOAPメッセージの転送方法が分かります。
soap:operation
この要素は、SOAP実装に必要な特定の操作Bindingを説明するためのもので、SOAPAction HTTPヘッダーによるサービス識別を示すsoapAction属性を含みます。
soap:body
このSOAP Binding要素を用いることで、入出力メッセージの詳細を説明できます。
WSDLは、異なるプログラミング言語間でウェブサービスを実装する際のプロセスを大いに簡素化する重要な記述言語です。WSDL文書は、サービスの内容と実行方法を定義し、各要素が連携してウェブサービスを分かりやすく説明します。
最新情報を購読