0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSDLの構成メモ

0
Posted at

はじめに

業務でSOAP通信による連携機能を実装する機会があったのですが、そこで出てくるWSDLの内容がよく分からなかったので、まとめました。

WSDLとは

「Web Services Description Language」の略。Webサービスの仕様をXML形式で記述したもの。SOAPと組み合わせて、インターネット上にWebサービスを提供するために使われることが多い。

構成

ルート要素はdefinitionsの配下に、次のような要素が定義されています。

  1. types
    • データ型(構造体)の定義
  2. message
    • 入出力データの定義
  3. portType
    • サービスが提供する操作(メソッド)のインターフェース
  4. binding
    • portType をどのプロトコル・形式で実装するか
  5. service
    • 実際のエンドポイント(URL)の定義

1. types

全体で使用するデータ構造(型)を定義する部分です。
ここで定義した要素や型、あるいは外部で定義された要素・型が後続のmessagepartなどから参照されます。

<types>
  <xsd:schema targetNamespace="http://example.com">
    <xsd:element name="GetUserRequest">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="userId" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:element>

    <xsd:element name="GetUserResponse">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="userName" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>
</types>

2. message

やり取りされるデータの構造を定義します。
messageは1つ以上のpartを持ち、各partがメッセージを構成する個々のパラメータを表します。
messageが「どの操作の入力/出力として使われるか」はportTypeoperationで指定します。

<message name="GetUserRequestMessage">
  <part name="parameters" element="tns:GetUserRequest" />
</message>
  
<message name="GetUserResponseMessage">
  <part name="parameters" element="tns:GetUserResponse" />
</message> 

3. portType

サービスが提供する操作(メソッド)を定義します。
どんな操作があり、どのmessageを入力・出力として扱うかを記述します。

<portType name="UserServicePortType">
  <operation name="GetUser">
    <input message="tns:GetUserRequestMessage"/>
    <output message="tns:GetUserResponseMessage"/>
  </operation>
</portType>

4. binding

portTypeの操作を、どのプロトコル・メッセージ形式で実装するかを記述します。

<binding name="UserServiceSoapBinding" type="tns:UserServicePortType">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="GetUser">
    <soap:operation soapAction="http://example.com/UserService/GetUser"/>
    <input><soap:body use="literal"/></input>
    <output><soap:body use="literal"/></output>
  </operation>
</binding>

5. service

クライアントが実際にアクセスするエンドポイント(URL) を定義します。

bindingが「どういうプロトコルでやり取りするか」を決めるのに対して、
serviceは「どこ(どの URL)にアクセスするか」を決めます。

<service name="UserService">
  <port name="UserServicePort" binding="tns:UserServiceSoapBinding">
    <soap:address location="https://example.com/userService"/>
  </port>
</service>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?