プログラミング

Webサービス Web APIのまとめ

スポンサーリンク

Webサービス Web APIを調べる

Webサービス、Web APIについて調べた結果を簡単にまとめました。

Webサービス、Web APIとは

HTTPなどの通信技術を使用してネットワーク上の機器間でXML形式メッセージの送受信を行う技術。
一般的にメッセージの送受信には、「SOAP」「REST」などのプロトコルを使用する。

Webサービスはプラットフォームに依存せず、他システムの部品として利用可能である特徴から、SOA(Service Oriented Architecture)のシステムを実現する手段として用いられることも多い。

SOAPとは

SOAP(Simple Object Access Protocol)の略。
メッセージの送受信共にSOAPメッセージと呼ばれるXML形式のデータで行います。
SOAPメッセージのインターフェイス仕様はWSDL(Web Services Description Language)などで確認することができます。
ツールにWSDLを読み込ませることでSOAPメッセージのテンプレートを作成することもできます。

RESTとは

REST(Representational State Transfer)の略。
メッセージの送信はHTTP、受信はXML形式のデータを受け取ります。
RESTサービスは、特定のURLにアクセスするだけでレスポンスが返ってくるので簡単に利用することができます。

SOAPとRESTの使い分け

SOAPかRESTどちらを選択するかは入力パラメータ数で判断します。
入力パラメータ数が少ない場合はREST、多い場合はSOAPを選択します。

SOAPとRESTの比較

メッセージ送受信方法の比較

 リクエストレスポンス
SOAPXMLXML
RESTHTTPXML

リクエスト、レスポンスの比較

SOAP Request

POST /GlobalWeather.asmx HTTP/1.1
Host: www.webservicex.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.webserviceX.NET/GetCitiesByCountry"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetCitiesByCountry xmlns="http://www.webserviceX.NET">
      <CountryName>string</CountryName>
    </GetCitiesByCountry>
  </soap:Body>
</soap:Envelope>

SOAP Responce

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">
      <GetCitiesByCountryResult>string</GetCitiesByCountryResult>
    </GetCitiesByCountryResponse>
  </soap:Body>
</soap:Envelope>

REST Request

GET /GlobalWeather.asmx/GetCitiesByCountry?CountryName=string HTTP/1.1
Host: www.webservicex.net

REST Responce

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.webserviceX.NET">string</string>

タイトルとURLをコピーしました